What is this server.R code doing?

shiny

#1

Hi all,

I'm new to Shiny and I'm trying to recreate/ understand the Data explorer tab 'SuperZip example' on rstudio website (https://shiny.rstudio.com/gallery/superzip-example.html).

Can anyone walk me through what the following server.R code is doing? I'm attempting to make my own selectInput() widgets that respond to each other by filtering available selections, similar to the relationship between "States" and "Cities" in the 'SuperZip example' above.

observe({
    cities <- if (is.null(input$states)) character(0) else {
      filter(cleantable, State %in% input$states) %>%
        `$`('City') %>%
        unique() %>%
        sort()
    }
    stillSelected <- isolate(input$cities[input$cities %in% cities])
    updateSelectInput(session, "cities", choices = cities,
                      selected = stillSelected)
  })

Thanks in advance!
Alex


#2

Have you looked at the "How to start Shiny" video tutorial at the link below, it's free, and the chapters are marked so you can get to the relevant components pretty easily:
https://shiny.rstudio.com/tutorial/


closed #3

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.