如何让 renderUI 对用户从下拉列表中选择不同的值做出反应,而无需单击我的提交按钮?
我有一个 wellPanel,其中包含 3 个内容:
1)我的下拉列表
2) 一组动态输入(由我的 renderUI 函数创建,取决于 #1 中的选择)
3)提交按钮
期望的行为:下拉选择的更改为用户提供了不同的输入小部件以供使用。当他们准备好获得所选输入的结果时,他们单击提交按钮,然后在主面板中获取结果。
问题:我的 renderUI 仅在单击提交按钮后对下拉选择做出反应。据我所知,我需要隔离某些内容或使用observeEvent,但我一直无法弄清楚。
简化示例:
rm(list = ls())
library(shiny)
ui <- fluidPage(
fluidRow(
column(4,wellPanel(
selectInput("analysis", label = "Type of Analysis:",
c("Award Total" = "total",
"Award Average" = "average"),
width = validateCssUnit("70%")),
uiOutput("filter_box"),
submitButton()
)),
column(8, textOutput("sample_text"))
)
)
server <- function(input, output, session){
output$filter_box <- renderUI({
if(input$analysis == "total"){
tagList(radioButtons(inputId = "input1", label = "Select One:",c("A", "B", "C"), selected = "A"))
} else {
tagList(checkboxGroupInput(inputId = "input2", label = "Select all that apply:",c("1","2","3","4","5")),
dateRangeInput(inputId = "input3", label = "Enter Date Range"))
}
})
output$sample_text <- renderText({
if(input$analysis == "total"){
input$input1
} else if(input$analysis == "average") {
c(input$input2, input$input3)
}
})
}
runApp(list(ui = ui, server = server))