0

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

3
  • 2
    Welcome to SO. Please give us more information and if possible a minimal reproducible example to allow us to help you. Commented 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 dashboard Commented Sep 7, 2018 at 9:11
  • 1
    As mentioned a code snippet containing a minimal reproducible example is best. Please see stackoverflow.com/help/mcve Commented Sep 7, 2018 at 10:15

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.