0

I need to have one selectInput to update on selected values in another selectInput and then use the updated one to select data from the dataset for plotting.

I use the following in ui:

selectizeInput("select_industry", "Industry groups",
                               choices = c(sort(unique(employ$industry_group))),
                               multiple = FALSE,
                               selected = 'Sector 10 - Information media & telecommunications (J)'
                ),
                uiOutput("select_industry_group")

and this is my server

#select industry
  output$select_industry_group <- renderUI({

    # check whether user wants to filter by cyl;
    # if not, then filter by selection
    if ("All industry groups" %in% input$select_industry) {
      dat <- employ
    } else {
      dat <- employ %>%
        filter(industry_group %in% input$select_industry)
    }

    # get available industry values
    group <- sort(unique(dat$var))

    # render selectizeInput
    selectizeInput("select_industry_item", "Industry",
                   choices = c(group),
                   multiple = FALSE,
                   selected="Communication services")
  })

#plot - industry

   output$employ1_plot<-renderPlotly({

      employ_ggplot<-employ%>%
         filter(var==input$select_industry_item)

...
   })

It returns an error... What am i doing wrong?

m45ha
  • 399
  • 1
  • 9
  • 1
    In your `renderPlotly` you should add `req(input$select_industry_item)` at the beginning, because the `selectInput` created via `renderUI` does not exist yet when the app starts. This could be the error. – Stéphane Laurent Apr 03 '23 at 07:41
  • Also, you can remove the need for `renderUI` by using `updateSelectInput` and making `employ` reactive. See, for example, [here](https://stackoverflow.com/questions/72562625/selectinput-update-inside-renderui-function-in-shiny-app). – Limey Apr 03 '23 at 07:49
  • Does this answer your question? [Reactively select column name from a table after reactively selecting that table from a list](https://stackoverflow.com/questions/73777659/reactively-select-column-name-from-a-table-after-reactively-selecting-that-table) – Meisam Apr 03 '23 at 09:20
  • thank you @StéphaneLaurent - that was spot on! – m45ha Apr 03 '23 at 22:23

0 Answers0