What is this server.R code doing?



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.

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

Thanks in advance!


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: