我想根据条件selectizeInput
s_l
更新input.c_l_check=='y'
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
而不是其值进行更新。
答案 0 :(得分: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)