【问题标题】:shiny conditional panel not updating闪亮的条件面板不更新
【发布时间】:2017-07-25 16:50:20
【问题描述】:

我对条件面板有疑问。我想在 sidebarPanel 中显示 DateRange 或 SliderInput,具体取决于 RadioButton 中的选择,该选项也在 sidebarPanel 中。

如果您尝试运行以下示例,它将失败并显示以下错误消息:

错误:形式参数“条件”与多个实际匹配 论据

如果您注释掉这两个条件中的任何一个,您可以看到 example 变量的值是 ab,具体取决于所选的选项。

我很确定我错过了什么,但我不知道是什么。我确实环顾四周,找不到任何有用的东西。

library(shiny)

# Server ---------------------------------------------

server = shinyServer(function(input, output){
  output$debug <- renderPrint({
    input$example
  })
})


# Ui -------------------------------------------------

ui = {
  fluidPage(
    sidebarPanel(
      radioButtons('example', 'Select Examples: ', choices = c('a', 'b'), selected = 'a'),
      conditionalPanel(
        condition = "input.example == 'a'",
        dateRangeInput('date', 'Select Date Range:',
                       start = Sys.Date() - 7,
                       end = Sys.Date(),
                       min = '2012-04-01',
                       max = Sys.Date()
                       )
        ,
        condition = "input.example == 'b'",
        sliderInput('date', 'Slide Date Range:', min = 1, max = 90, value = 14, step = 1)
       )
    ),
    mainPanel(verbatimTextOutput("debug")
    )
  )}


# App ------------------------------------------------

shinyApp(ui = ui, server = server)

谢谢

【问题讨论】:

    标签: r shiny reactive-programming


    【解决方案1】:

    您需要指定两个 conditionalPanel 对象,每个条件一个。

    library(shiny)
    
    # Server ---------------------------------------------
    
    server = shinyServer(function(input, output){
      output$debug <- renderPrint({
        input$example
      })
    })
    
    
    # Ui -------------------------------------------------
    
    ui = {
      fluidPage(
        sidebarPanel(
          radioButtons('example', 'Select Examples: ', choices = c('a', 'b'), 
               selected = 'a'),
        conditionalPanel(
          condition = "input.example == 'a'",
          dateRangeInput('date', 'Select Date Range:',
                       start = Sys.Date() - 7,
                       end = Sys.Date(),
                       min = '2012-04-01',
                       max = Sys.Date()
        )
      ),
      conditionalPanel(
        condition = "input.example = 'b'",
        sliderInput('date', 'Slide Date Range:', min = 1, max = 90, value = 14, 
              step = 1)
      )
    ),
    mainPanel(verbatimTextOutput("debug")
    )
    )}
    
    
    # App ------------------------------------------------
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 2015-09-17
      • 2017-04-29
      • 2016-04-10
      • 2021-04-06
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多