【发布时间】:2018-04-14 13:31:37
【问题描述】:
我正在构建一个 Rshiny 仪表板,并正在努力集成 Shiny 的一些更具交互性的功能,并且目前正在使用 renderUI 功能,它(我相信应该)根据另一个输入的值创建额外的小部件/输入参数范围。我遇到了一个简单的错误,但在调试时遇到了困难。下面是一个带有相关代码的演示:
choices = c('All', 'None')
names(choices) = choices
ui <- fluidPage(theme = shinytheme('united'),
# create permanent input for shot chart type (should be 5 options)
selectInput(inputId = 'choice.input', label = 'Select a choice', multiple = FALSE,
choices = choices, selected = 'All'),
uiOutput('secondinput')
)
server <- shinyServer(function(input, output) {
if(input$choice.input == 'All') {
my.second.input <- c('a', 'b', 'c', 'd', 'e')
names(my.second.input) <- my.second.input
# player parameter for player whose shot chart will be shown
output$secondinput <- renderUI({
selectInput(inputId = 'another.input', label = 'Check this input', multiple = FALSE,
choices = my.second.input, selected = 'a')
})
}
})
shinyApp(ui, server)
我不确定这里出了什么问题 - 我认为我在服务器函数中使用 renderUI() 并且名称匹配 (output$secondinput, uiOutput('secondinput')) 是正确的,但这会引发我的错误...
请注意,我的完整代码有多个选项用于choice.input,并且我希望在服务器中为每个 (4-5)choice.input() 值设置一个 if() 案例。感谢您对此处出现问题的任何帮助,谢谢!
编辑 - 澄清一下,带有标签“选择一个选项”的选择输入choice.input 应该始终显示。当此输入设置为“全部”时,我希望显示一个附加输入,即第二个输入。如果choice.input 未设置为“全部”,那么我不希望显示第二个输入。希望这会有所帮助。
【问题讨论】: