【问题标题】:Shiny: conditional update of SelectizeInput based on selected levelsShiny:基于选定级别的 SelectizeInput 条件更新
【发布时间】: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 而不是它的值进行更新。

【问题讨论】:

    标签: r shiny


    【解决方案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是否可以回答?
    猜你喜欢
    • 1970-01-01
    • 2018-09-01
    • 2019-07-31
    • 2015-06-01
    • 2021-12-13
    • 2019-05-20
    • 2020-08-03
    • 2022-10-23
    • 1970-01-01
    相关资源
    最近更新 更多