![](/img/trans.png)
[英]Why toggleState does not work with modalDialog in R Shiny?
[英]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.