diff --git a/NEWS.md b/NEWS.md index b355796fa7..a3c029c5ff 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ### Enhancements +* Added option to choose which variables can be filtered in the filter panel by using the `filterable` attributes for the per-dataset lists in the `filter` argument of `init`. * `teal_module` having `data` argument in its arguments will receive a list of reactive filter data with `"code"` and `"join_keys"` attributes. * Updated the internals of `module_teal` to reflect changes in `teal.slice`. * `teal_module` having `filter_panel_api` argument in its arguments will receive a `FilterPanelAPI` object. diff --git a/R/init.R b/R/init.R index e36f1426f8..283218f23b 100644 --- a/R/init.R +++ b/R/init.R @@ -86,6 +86,9 @@ #' ) #' ) #' ``` +#' By adding the `filterable` attribute it is possible to control which variables can be filtered for each +#' dataset. See the example below where `ADSL` can only be filtered by `AGE`, `SEX` or `RACE`. +#' #' @param header (`character` or `shiny.tag`) \cr #' the header of the app. Note shiny code placed here (and in the footer #' argument) will be placed in the app's `ui` function so code which needs to be placed in the `ui` function @@ -137,7 +140,7 @@ #' ) #' ), #' title = "App title", -#' filter = list(ADSL = list(AGE = list())), +#' filter = list(ADSL = structure(list(AGE = list()), filterable = c("AGE", "SEX", "RACE"))), #' header = tags$h1("Sample App"), #' footer = tags$p("Copyright 2017 - 2020") #' ) diff --git a/R/module_tabs_with_filters.R b/R/module_tabs_with_filters.R index 02ee21acba..6b8855f1a8 100644 --- a/R/module_tabs_with_filters.R +++ b/R/module_tabs_with_filters.R @@ -153,6 +153,12 @@ srv_tabs_with_filters <- function(id, datasets, modules, reporter = teal.reporte logger::log_trace( "srv_tabs_with_filters initializing the module with datasets { paste(datasets$datanames(), collapse = ' ') }." ) + + # set filterable variables for each dataset + for (filter_dataname in names(filter)) { + datasets$set_filterable_varnames(filter_dataname, attr(filter[[filter_dataname]], "filterable")) + } + active_module <- srv_nested_tabs(id = "root", datasets = datasets, modules = modules, reporter = reporter) active_datanames <- eventReactive( diff --git a/man/init.Rd b/man/init.Rd index 8ae40b59d4..b3d191be5e 100644 --- a/man/init.Rd +++ b/man/init.Rd @@ -91,7 +91,10 @@ different way. Since it contains patient data with list of experiments, ) ) ) -}\if{html}{\out{}}} +}\if{html}{\out{}} + +By adding the \code{filterable} attribute it is possible to control which variables can be filtered for each +dataset. See the example below where \code{ADSL} can only be filtered by \code{AGE}, \code{SEX} or \code{RACE}.} \item{header}{(\code{character} or \code{shiny.tag}) \cr the header of the app. Note shiny code placed here (and in the footer @@ -152,7 +155,7 @@ app <- init( ) ), title = "App title", - filter = list(ADSL = list(AGE = list())), + filter = list(ADSL = structure(list(AGE = list()), filterable = c("AGE", "SEX", "RACE"))), header = tags$h1("Sample App"), footer = tags$p("Copyright 2017 - 2020") ) diff --git a/man/srv_tabs_with_filters.Rd b/man/srv_tabs_with_filters.Rd index a2b1cc1348..5a3695ef37 100644 --- a/man/srv_tabs_with_filters.Rd +++ b/man/srv_tabs_with_filters.Rd @@ -89,7 +89,10 @@ different way. Since it contains patient data with list of experiments, ) ) ) -}\if{html}{\out{}}} +}\if{html}{\out{}} + +By adding the \code{filterable} attribute it is possible to control which variables can be filtered for each +dataset. See the example below where \code{ADSL} can only be filtered by \code{AGE}, \code{SEX} or \code{RACE}.} } \value{ \code{reactive} currently selected active_module diff --git a/man/srv_teal.Rd b/man/srv_teal.Rd index 9cfd14ba0f..b1cd99094d 100644 --- a/man/srv_teal.Rd +++ b/man/srv_teal.Rd @@ -80,7 +80,10 @@ different way. Since it contains patient data with list of experiments, ) ) ) -}\if{html}{\out{}}} +}\if{html}{\out{}} + +By adding the \code{filterable} attribute it is possible to control which variables can be filtered for each +dataset. See the example below where \code{ADSL} can only be filtered by \code{AGE}, \code{SEX} or \code{RACE}.} } \value{ \code{reactive} which returns the currently active module diff --git a/man/srv_teal_with_splash.Rd b/man/srv_teal_with_splash.Rd index 81297b9c6e..ee726529f9 100644 --- a/man/srv_teal_with_splash.Rd +++ b/man/srv_teal_with_splash.Rd @@ -87,7 +87,10 @@ different way. Since it contains patient data with list of experiments, ) ) ) -}\if{html}{\out{}}} +}\if{html}{\out{}} + +By adding the \code{filterable} attribute it is possible to control which variables can be filtered for each +dataset. See the example below where \code{ADSL} can only be filtered by \code{AGE}, \code{SEX} or \code{RACE}.} } \value{ \code{reactive}, return value of \code{\link[=srv_teal]{srv_teal()}}