簡體   English   中英

shinyjs::toggleState 不適用於 renderUI 中產生的輸入

[英]shinyjs::toggleState does not work with input produced in renderUI

在以下應用程序中,用戶應上傳csv數據集文件和 select 列以進行進一步處理。 可供選擇的列當然取決於上傳的文件。 因此,實現選項的下拉菜單是通過renderUI動態生成的。

我想使用shinyjs::toggleState禁用下拉菜單,直到數據集實際上傳。 不幸的是,這不起作用。 有人知道為什么和/或有解決方法嗎?

非常感謝!

library(shiny)
library(shinyjs)

ui <- fluidPage(
  useShinyjs(),
  fileInput("file", "Choose a File"),
  uiOutput("select")
)

server <- function(input, output) {
  dataset <- reactive({
    if(is.null(input$file))
      NULL
    else
      read.csv(input$file$datapath)
  })
  output$select <- renderUI({
    if(is.null(dataset()))
      choices <- "this should not be selectable!"
    else
      choices <- colnames(dataset())
    selectizeInput("choose", "Choose a Column", choices=choices)
  })
  observe({
    toggleState("choose", !is.null(dataset()))
  })
}

shinyApp(ui=ui, server=server)
library(shiny)
library(shinyjs)

ui <- fluidPage(
  useShinyjs(),
  fileInput("file", "Choose a File"),
  uiOutput("select")
)

server <- function(input, output) {
  dataset <- reactive({
    if(is.null(input$file))
      NULL
    else
      read.csv(input$file$datapath)
  })
  output$select <- renderUI({
    if(is.null(dataset()))
      choices <- "this should not be selectable!"
    else
      choices <- colnames(dataset())
    selectizeInput("choose", "Choose a Column", choices=choices)
  })
  observe({
    req(input$choose)
    toggleState("choose", !is.null(dataset()))
  })
}

shinyApp(ui=ui, server=server)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM