I am using R and crosstalk (without Shiny) to create two filters. In the below example they are a department filter and a provider filter. The functionality I’m looking for is when I select a department from the department filter, the provider filter will update to only include providers that are in the department selected in the department filter.
In the example below, when I select the Department of Cardiology, I only want the values of Dr.A, Dr.B and Dr.C in the filter for providers
library(tidyverse)
library(crosstalk)
data <- data.frame(
Department = rep(c("Cardiology", "Neurology", "Pediatrics"), each = 3),
Provider = c("Dr. A", "Dr. B", "Dr. C", "Dr. D", "Dr. E", "Dr. F", "Dr. G", "Dr. H", "Dr. I")
,value = seq(1:9)
)
# Create a shared data object
shared_data <- SharedData$new(data,~Department)
# Output table
bscols(
widths = c(12),
list(filter_select(
id = "department_filter",
label = "Select Department",
sharedData = shared_data,
group = ~Department
,multiple = FALSE
),
filter_select(
id = "provider_filter",
label = "Select Provider",
sharedData = shared_data,
group = ~Provider)
,multiple = FALSE)
,datatable(shared_data)
)
Currently, both filters do filter the table, however, when I select the department of Cardiology, all providers are still in the provider filter.