0

I want to update the Pickerinput with change in another PickerInput.How can I do it in server side in Shiny?

  • 2
    Welcome to SO. Please give us more information and if possible a minimal reproducible example to allow us to help you. – Eli Berkow Sep 07 '18 at 08: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 dashboard – shantanu garg Sep 07 '18 at 09:11
  • 1
    As mentioned a code snippet containing a minimal reproducible example is best. Please see https://stackoverflow.com/help/mcve – Eli Berkow Sep 07 '18 at 10:15

1 Answers1

4

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)
}

Output: example

Artem
  • 3,304
  • 3
  • 18
  • 41