I have 1 input in Rshiny that needs multiple inputs:
selectInput("selected_herd", "Select Herd", selected = herds_list[1], choices = herds_list, multiple = TRUE)
In the application, while I am adding multiple herds, the app refreshes the data before I hit enter. Is there anyway to stop this? and make the app refresh data only after I finish the input list and hit enter?
In the photo attached, you can see that I am about to start entering the list of herds, but the app already refreshes the data on an empty list and show errors.
What I want is the app to show result of the previous selection(photo 2) until I finish new selection and hit enter.
Anyone knows how to do this? Thank you very much!!!
The traditional way in Shiny is to add a button (or any comparable widget) that must be clicked for the input to apply. On the server side you can bind the corresponding reactives to an event (like a button press) using bindEvent()
. This means that the reactive expression can only be evaluated once the event is triggered.
Since you didn't share any code, I created a simple dummy example. Note that bindEvent()
can be used with any type of event, not just a button.
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fluidPage(
selectInput(
"select",
label = "Select Herd",
choices = c("BBBJ", "BBBX", "BBFC", "BBFD", "BBFG"),
multiple = TRUE
),
actionButton("go", "Apply changes")
)
),
mainPanel(
uiOutput("result")
)
)
)
server <- function(input, output) {
result <- reactive({
lst <- lapply(input$select, tags$li)
paste("Selected:<br>", do.call(tags$ul, lst))
})
output$result <- renderUI({
HTML(result())
}) %>%
bindEvent(input$go)
}
runApp(shinyApp(ui, server))