How to make renderUI respond to a user who selects different values from a drop-down list without having to click on my submitButton?
I have a wellPanel that contains 3 things:
1) My drop-down list
2) A set of dynamic inputs (created by my renderUI function, depends on the choice in # 1)
3) submitButton
Desired behavior: Changes to the drop-down list give the user different input widgets. When they are ready for the results of their selected inputs, they click the submitButton button and they get their results in the mainPanel.
Problem: my renderUI only reacts to the dropdown after clicking submitButton. As far as I can tell, I need to isolate something or use observEvent, but I could not figure it out.
A simplified example:
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))