【发布时间】:2017-07-25 16:50:20
【问题描述】:
我对条件面板有疑问。我想在 sidebarPanel 中显示 DateRange 或 SliderInput,具体取决于 RadioButton 中的选择,该选项也在 sidebarPanel 中。
如果您尝试运行以下示例,它将失败并显示以下错误消息:
错误:形式参数“条件”与多个实际匹配 论据
如果您注释掉这两个条件中的任何一个,您可以看到 example 变量的值是 a 或 b,具体取决于所选的选项。
我很确定我错过了什么,但我不知道是什么。我确实环顾四周,找不到任何有用的东西。
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