条件面板有问题。我想在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)
由于
答案 0 :(得分: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)