闪亮:根据所选级别对SelectizeInput进行条件更新

时间:2017-06-05 08:23:37

标签: r shiny

我想根据条件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而不是其值进行更新。

1 个答案:

答案 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)