teal
teal copied to clipboard
Filter mapping by module ID instead of module label
Conceptually, I find it quite odd to map filter to module labels. It should be a module identifier instead. A label should be a free text but we tend to use it as identifier which is probably not the right thing to do.
@donyunardi comment from #972
Currently, this is how users define module specific mapping
app <- init(
data = cdisc_data(...),
modules = teal::modules(
teal.modules.general::tm_data_table(
label = "ADS Data Table",
variables_selected = list(ADSL = c("STUDYID", "USUBJID", "SUBJID", "SITEID", "AGE", "SEX", "COUNTRY")),
dt_args = list(caption = "ADSL Table Caption")
),
filter = teal_slices(
teal_slice("ADSL", "COUNTRY", "country", selected = "USA", fixed = TRUE),
teal_slice("ADSL", "ETHNIC", "ethnic", anchored = TRUE),
module_specific = TRUE,
mapping = list(
"ADS Data Table" = c("country", "ethnic") # using the module's label to assign filters
)
)
)
We have an assertion to check for duplicate labels, which is good.
However, can we explore the possibility of using a module's id
for this assignment? This could involve altering the module's structure and introducing the id
in the module's server.
Here's what the code could look like:
app <- init(
data = cdisc_data(...),
modules = teal::modules(
teal.modules.general::tm_data_table(
id = "module1",
label = "ADS Data Table",
variables_selected = list(ADSL = c("STUDYID", "USUBJID", "SUBJID", "SITEID", "AGE", "SEX", "COUNTRY")),
dt_args = list(caption = "ADSL Table Caption")
),
filter = teal_slices(
teal_slice("ADSL", "COUNTRY", "country", selected = "USA", fixed = TRUE),
teal_slice("ADSL", "ETHNIC", "ethnic", anchored = TRUE),
module_specific = TRUE,
mapping = list(
"module1" = c("country", "ethnic") # using the module's id to assign filters
)
)
)