I want to update the Pickerinput with change in another PickerInput.How can I do it in server side in Shiny?
3
-
2Welcome to SO. Please give us more information and if possible a minimal reproducible example to allow us to help you.Eli Berkow– Eli Berkow2018-09-07 08:36:29 +00:00Commented Sep 7, 2018 at 8:36
-
I have two pickerInput with same choices as :choices = colnames(intangible_features[,c(30:34)]) .If user selects one option from pickerinput , another pickerinput get updated also on the same dashboardshantanu garg– shantanu garg2018-09-07 09:11:17 +00:00Commented Sep 7, 2018 at 9:11
-
1As mentioned a code snippet containing a minimal reproducible example is best. Please see stackoverflow.com/help/mcveEli Berkow– Eli Berkow2018-09-07 10:15:44 +00:00Commented Sep 7, 2018 at 10:15
Add a comment
|
1 Answer
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)
}
