0

I am trying to create "nested" (or cascading) filters using Flexdash and crosstalk. I would like to have two filters, "State", and "City", where the options for City are displayed based on the selected State. I cannot use Shiny as it is not an approved software at my company.

Here is an example:

    ---
    title: "testFlexdash"
    output: 
    flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
    ---

    ```{r setup, include=FALSE}
    library(flexdashboard)
    library(tidyverse)
    library(htmlwidgets)
    library(crosstalk)
    library(plotly)
    #Example data
    df <- data.frame(State = c("Maine", "Maine", "Maine", "Vermont", "Vermont", "Vermont", "Wisconsin", "Wisconsin", "Wisconsin", "Maine", "Maine", "Maine", "Vermont", "Vermont", "Vermont", "Wisconsin", "Wisconsin", "Wisconsin"),
    City = c("Portland", "Rockland", "Ellsworth", "Burlington", "Brattleboro", "Green Mountain", "Madison", "Bayfield", "Oshkosh", "Portland", "Rockland", "Ellsworth", "Burlington", "Brattleboro", "Green Mountain", "Madison", "Bayfield", "Oshkosh"), Value = c(10, 98, 11, 44, 72, 34, 9, 19, 77, 67, 85, 2, 58, 88, 15, 29, 30, 12), Year = c("2011", "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2017", "2017", "2017", "2017", "2017", "2017", "2017", "2017", "2017"))

    #Crosstalk shared data
    df_shared <- SharedData$new(df)

Inputs {.sidebar}

    #Filters that I would like to link to each other:

    filter_select(id = "state", 
                  label = "State:", 
                  sharedData = df_shared, 
                  group = ~State)

    filter_select(id = "city", 
                  label = "City:", 
                  sharedData = df_shared, 
                  group = ~City, 
                  allLevels = FALSE)
    #Example Plot
    df_shared %>% 
    plot_ly(x = ~City, y = ~Value, color = ~Year, type = "bar")

I have tried filtering the shared dataframe in the filter_select argument and it did not work. Using allLevels = F did not change anything. How would I go about linking these filters? Thanks!

Hallie
  • 1
  • 2

0 Answers0