Filters and Sub-filters in Flex Dashboard

33 views Asked by At

Im trying to have an input column where you can select more than one filter.

Then based off of those inputs I want to have sub-filters in my Flex Dashboard.

So for example if i have a database with columns : states, numbers, years, car_makes I want to select states and car_makes and then have two sub-filters where I can go and select what states and car_markes I want.

Im having a really hard time creating these sub-filters in my dashboard and in my code.

filter - would have options : states, numbers, years, car_makes You can select more than one filter

Sub-Filter

data.choices1 <- reactive({
  ifelse(any(input$filter == colnames(data))){
    unique(pol_data$sub_filter)
  } else { 
    unique(veh_data$sub_filter)
}
  })



renderUI({selectInput("sub_filter", label = "Select how to Filter in Columns",
                      choices = sort(data.choices1()), multiple = TRUE )})

I tried for functions, I tried if functions. Im having a hard time pasting the filter input into my subfilter. In my dashboard when I select a filter, my sub-filter wont populate.

I tried for functions, and case_when functions by trying to select a column number that I can then go off but I was not able to make it work.

I tried to wrap everything in a reactive function, but that didnt work.

1

There are 1 answers

0
Ala Rosow On
data.choices1 <-  reactive({
  if(input$filter[1] %in% colnames(pol_data)){ 
    unique(pol_data[,input$filter[1]])
  } else {
    unique(veh_data[,input$filter[1]])
  }
})

updating my data.choices1 to the above now lets me select sub filters from each one. However i do get an error if there is no filters selected and Im working on that now