2017-07-25 79 views
0

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

感謝

回答

0

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