2
votes

I have every unique value under the market column saved to a variable, which is saved as options to a drop down menu. And when a viewer selects a market in the shiny, s/he will see the data filtered to the market chosen. I am trying to incorporate a blank option into my dplyr expression to allow a viewer see the entire dataset without any filter by market. The way I built my shiny app, however, it seems that I need to select a market for it to work properly.

I am curious if there is an easier way to add a blank option so if a viewer did not want to filter by market at all, it would show the entire df?

The code below shows what I have so far.

market_choices <- c("north","south","east","west")

selectInput(inputId = "mkt", 
            label = "Select Market", 
            choices = market_choices, 
            selected = "east"))

  test <- reactive({df %>% filter(Market == input$mkt)})
1

1 Answers

2
votes

You could include an all option in market_choices, and then put the filter expression in a conditional statement:

market_choices <- c("north","south","east","west", 'all')
...
test <- reactive({if(input$mkt == 'all') {
                      df
                  } else {
                      df %>% filter(Market == input$mkt)
                  }})