Shiny:基于选定级别的 SelectizeInput 条件更新
Posted
技术标签:
【中文标题】Shiny:基于选定级别的 SelectizeInput 条件更新【英文标题】:Shiny: conditional update of SelectizeInput based on selected levels 【发布时间】:2017-11-05 23:25:57 【问题描述】:我想根据条件input.c_l_check=='y'
使用选定的值s_l
更新selectizeInput
ShinyUi <- fluidPage(
sidebarLayout(
sidebarPanel(
checkboxGroupInput('s_l', 'D to show:', levels(data$D), selected = levels(data$D)),
radioButtons("c_l_check", "D to colour:", list("Yes"='y', "No"='n'), selected = 'n'),
conditionalPanel( condition = "input.c_l_check=='y'",
selectizeInput( inputId = "c_l", label = "D to color:", multiple = T, choices = NULL))
...
))
ShinyServer <- function(input, output, session)
# Updating selectize input
updateSelectizeInput(session, 'c_l', choices = 'input$s_l', server = TRUE)
...
# Run the application
shinyApp(ui = ShinyUi, server = ShinyServer)
但是,它使用input$s_l
而不是它的值进行更新。
【问题讨论】:
【参考方案1】:应该是:
updateSelectizeInput(session, 'c_l', choices = input$s_l, server = TRUE)
即input$s_l
应该不带引号。
编辑:
这是一个工作示例:
data <- data.frame(D = iris$Species)
ShinyUi <- fluidPage(
sidebarLayout(
sidebarPanel(
checkboxGroupInput('s_l', 'D to show:', levels(data$D), selected = levels(data$D)),
radioButtons("c_l_check", "D to colour:", list("Yes"='y', "No"='n'), selected = 'n'),
conditionalPanel( condition = "input.c_l_check=='y'",
selectizeInput( inputId = "c_l", label = "D to color:", multiple = T, choices = NULL))
),
mainPanel()
))
ShinyServer <- function(input, output, session)
observe(
# Updating selectize input
updateSelectizeInput(session, 'c_l', choices = input$s_l, server = TRUE)
)
# Run the application
shinyApp(ui = ShinyUi, server = ShinyServer)
【讨论】:
它给出的值是s_l
,而不是levels(data$D)
。如果你已经有一个可行的例子,请指点我。
observe
是解决方案的关键。成功了,谢谢!在场边,你能看看this是否可以回答?以上是关于Shiny:基于选定级别的 SelectizeInput 条件更新的主要内容,如果未能解决你的问题,请参考以下文章
R Shiny - 我无法从selectInput操作中检索选定的输出值