簡體   English   中英

閃亮的條件面板未更新

[英]shiny conditional panel not updating

我有條件面板的問題。 我想在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)

謝謝

您需要指定兩個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