Reputation: 31
I want to update the Pickerinput with change in another PickerInput.How can I do it in server side in Shiny?
Upvotes: 0
Views: 2657
Reputation: 3414
You could use observeEvent
function at the server side to monitor the status of pickerInput
#1 then use updatePickerInput
function to update pickerInput
#2.
Please see the code below, which takes the first letter in pickerInput
#1 and chooses the content of pickerInput
#2 accordingly:
library("shiny")
library("shinyWidgets")
ui <- fluidPage(
tags$h2("Update pickerInput"),
fluidRow(
column(
width = 5, offset = 1,
pickerInput(
inputId = "p1",
label = "Starting Letters",
choices = LETTERS
)
),
column(
width = 5,
pickerInput(
inputId = "p2",
label = "Names of Cars",
choices = ""
)
)
)
)
server <- function(input, output, session) {
observeEvent(input$p1, {
updatePickerInput(session = session, inputId = "p2",
choices = grep(paste0("^",input$p1), rownames(mtcars), value = TRUE))
}, ignoreInit = TRUE)
}
shinyApp(ui = ui, server = server)
}
Upvotes: 4