简体   繁体   English

闪亮的条件面板未更新

[英]shiny conditional panel not updating

I have an issue with conditional panel. 我有条件面板的问题。 I would like to show in sidebarPanel either DateRange OR SliderInput depending on the selected choice in the RadioButton, which is also in the sidebarPanel. 我想在sidebarPanel中显示DateRange或SliderInput,这取决于RadioButton中的所选选项,该按钮也在sidebarPanel中。

If you try to run the below example it will fail with following Error message: 如果尝试运行以下示例,它将失败,并显示以下错误消息:

Error : formal argument "condition" matched by multiple actual arguments 错误:形式参数“条件”与多个实际参数匹配

If you comment out any of the two conditions you can see that the example variable has value a or b depending on the options chosen. 如果注释掉这两个条件中的任何一个,则可以看到example变量的值ab取决于所选择的选项。

I'm pretty sure I'm missing something, but I cannot figure out what. 我很确定我缺少什么,但是我无法弄清楚是什么。 I did look around and I couldn't find anything helpful. 我确实环顾四周,找不到任何帮助。

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)

Thanks 谢谢

You need to specify two conditionalPanel objects, one for each condition. 您需要指定两个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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM