diff --git a/NEWS.md b/NEWS.md index e642796337..493adad67d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ ### Breaking changes * Specifying `filter` argument in `teal::init` requires `teal_slices` object now. Details in documentation of `teal::init`. +* Soft deprecated `filters` argument in `module` and replaced it with `datanames`. Details in documentation of `teal::module` ### Miscellaneous diff --git a/R/dummy_functions.R b/R/dummy_functions.R index c742a2d70b..cf0c0116d4 100644 --- a/R/dummy_functions.R +++ b/R/dummy_functions.R @@ -93,7 +93,7 @@ example_datasets <- function() { # nolint #' shinyApp(app$ui, app$server) #' } #' @export -example_module <- function(label = "example teal module", filters = "all") { +example_module <- function(label = "example teal module", datanames = "all") { checkmate::assert_string(label) module( label, @@ -110,7 +110,7 @@ example_module <- function(label = "example teal module", filters = "all") { encoding = selectInput(ns("dataname"), "Choose a dataset", choices = names(data)) ) }, - filters = filters + datanames = datanames ) } @@ -130,13 +130,13 @@ example_modules <- function(datanames = c("ADSL", "ADTTE")) { label = "d2", modules( label = "d3", - example_module(label = "aaa1", filters = datanames), - example_module(label = "aaa2", filters = datanames), - example_module(label = "aaa3", filters = datanames) + example_module(label = "aaa1", datanames = datanames), + example_module(label = "aaa2", datanames = datanames), + example_module(label = "aaa3", datanames = datanames) ), - example_module(label = "bbb", filters = datanames) + example_module(label = "bbb", datanames = datanames) ), - example_module(label = "ccc", filters = datanames) + example_module(label = "ccc", datanames = datanames) ) return(mods) } diff --git a/R/init.R b/R/init.R index 745ddfbb38..ea98d7254e 100644 --- a/R/init.R +++ b/R/init.R @@ -70,7 +70,7 @@ #' label = "data source", #' server = function(input, output, session, data) {}, #' ui = function(id, ...) div(p("information about data source")), -#' filters = "all" +#' datanames = "all" #' ), #' example_module(label = "example teal module"), #' module( @@ -84,7 +84,7 @@ #' ns <- NS(id) #' plotOutput(ns("hist")) #' }, -#' filters = "new_iris" +#' datanames = "new_iris" #' ) #' ), #' title = "App title", @@ -144,10 +144,10 @@ init <- function(data, modules$children <- sapply(modules$children, resolve_modules_datanames, simplify = FALSE) modules } else { - modules$filters <- if (identical(modules$filters, "all")) { + modules$datanames <- if (identical(modules$datanames, "all")) { datanames - } else if (is.character(modules$filters)) { - datanames_adjusted <- intersect(modules$filters, datanames) + } else if (is.character(modules$datanames)) { + datanames_adjusted <- intersect(modules$datanames, datanames) include_parent_datanames(dataname = datanames_adjusted, join_keys = join_keys) } modules diff --git a/R/module_nested_tabs.R b/R/module_nested_tabs.R index 0713a3b4dc..443587b07e 100644 --- a/R/module_nested_tabs.R +++ b/R/module_nested_tabs.R @@ -61,7 +61,8 @@ NULL #' @rdname module_nested_tabs ui_nested_tabs <- function(id, modules, datasets, depth = 0L, is_module_specific = FALSE) { - checkmate::assert_int(depth) + checkmate::assert_multi_class(modules, c("teal_modules", "teal_module")) + checkmate::assert_count(depth) UseMethod("ui_nested_tabs", modules) } @@ -133,7 +134,7 @@ ui_nested_tabs.teal_module <- function(id, modules, datasets, depth = 0L, is_mod ) ) - if (!is.null(modules$filter) && is_module_specific) { + if (!is.null(modules$datanames) && is_module_specific) { fluidRow( column(width = 9, teal_ui, class = "teal_primary_col"), column( @@ -150,6 +151,7 @@ ui_nested_tabs.teal_module <- function(id, modules, datasets, depth = 0L, is_mod #' @rdname module_nested_tabs srv_nested_tabs <- function(id, datasets, modules, is_module_specific = FALSE, reporter = teal.reporter::Reporter$new()) { + checkmate::assert_multi_class(modules, c("teal_modules", "teal_module")) checkmate::assert_class(reporter, "Reporter") UseMethod("srv_nested_tabs", modules) } @@ -166,6 +168,7 @@ srv_nested_tabs.default <- function(id, datasets, modules, is_module_specific = srv_nested_tabs.teal_modules <- function(id, datasets, modules, is_module_specific = FALSE, reporter = teal.reporter::Reporter$new()) { checkmate::assert_list(datasets, types = c("list", "FilteredData")) + moduleServer(id = id, module = function(input, output, session) { logger::log_trace("srv_nested_tabs.teal_modules initializing the module { deparse1(modules$label) }.") @@ -180,7 +183,8 @@ srv_nested_tabs.teal_modules <- function(id, datasets, modules, is_module_specif is_module_specific = is_module_specific, reporter = reporter ) - } + }, + simplify = FALSE ) # when not ready input$active_tab would return NULL - this would fail next reactive @@ -203,12 +207,13 @@ srv_nested_tabs.teal_modules <- function(id, datasets, modules, is_module_specif #' @export srv_nested_tabs.teal_module <- function(id, datasets, modules, is_module_specific = TRUE, reporter = teal.reporter::Reporter$new()) { - checkmate::assert_class(datasets, class = "FilteredData") + checkmate::assert_class(datasets, "FilteredData") logger::log_trace("srv_nested_tabs.teal_module initializing the module: { deparse1(modules$label) }.") + moduleServer(id = id, module = function(input, output, session) { modules$server_args <- teal.transform::resolve_delayed(modules$server_args, datasets) - if (!is.null(modules$filter) && is_module_specific) { - datasets$srv_filter_panel("module_filter_panel", active_datanames = reactive(modules$filter)) + if (!is.null(modules$datanames) && is_module_specific) { + datasets$srv_filter_panel("module_filter_panel", active_datanames = reactive(modules$datanames)) } # Create two triggers to limit reactivity between filter-panel and modules. @@ -288,14 +293,17 @@ srv_nested_tabs.teal_module <- function(id, datasets, modules, is_module_specifi #' #' @keywords internal .datasets_to_data <- function(module, datasets, trigger_data = reactiveVal(1L)) { + checkmate::assert_class(module, "teal_module") + checkmate::assert_class(datasets, "FilteredData") checkmate::assert_class(trigger_data, "reactiveVal") - datanames <- if (is.null(module$filter)) datasets$datanames() else module$filter + + datanames <- if (is.null(module$datanames)) datasets$datanames() else module$datanames # list of reactive filtered data data <- sapply( - USE.NAMES = TRUE, - X = datanames, - FUN = function(x) eventReactive(trigger_data(), datasets$get_data(x, filtered = TRUE)) + datanames, + function(x) eventReactive(trigger_data(), datasets$get_data(x, filtered = TRUE)), + simplify = FALSE ) hashes <- calculate_hashes(datanames, datasets) @@ -327,11 +335,5 @@ srv_nested_tabs.teal_module <- function(id, datasets, modules, is_module_specifi #' @keywords internal #' calculate_hashes <- function(datanames, datasets) { - sapply( - datanames, - simplify = FALSE, - function(x) { - rlang::hash(datasets$get_data(x, filtered = FALSE)) - } - ) + sapply(datanames, function(x) rlang::hash(datasets$get_data(x, filtered = FALSE)), simplify = FALSE) } diff --git a/R/module_snapshot_manager.R b/R/module_snapshot_manager.R index 72da2e18fd..cbc76e8c45 100644 --- a/R/module_snapshot_manager.R +++ b/R/module_snapshot_manager.R @@ -152,13 +152,13 @@ snapshot_manager_srv <- function(id, slices_global, mapping_matrix, filtered_dat snapshot_state <- as.teal_slices(snapshot) mapping_unfolded <- unfold_mapping(attr(snapshot_state, "mapping"), names(filtered_data_list)) mapply( - function(filtered_data, filters) { + function(filtered_data, filter_ids) { filtered_data$clear_filter_states(force = TRUE) - slices <- Filter(function(x) x$id %in% filters, snapshot_state) + slices <- Filter(function(x) x$id %in% filter_ids, snapshot_state) filtered_data$set_filter_state(slices) }, filtered_data = filtered_data_list, - filters = mapping_unfolded + filter_ids = mapping_unfolded ) slices_global(snapshot_state) removeModal() @@ -186,13 +186,13 @@ snapshot_manager_srv <- function(id, slices_global, mapping_matrix, filtered_dat snapshot_state <- as.teal_slices(snapshot) mapping_unfolded <- unfold_mapping(attr(snapshot_state, "mapping"), names(filtered_data_list)) mapply( - function(filtered_data, filters) { + function(filtered_data, filter_ids) { filtered_data$clear_filter_states(force = TRUE) - slices <- Filter(function(x) x$id %in% filters, snapshot_state) + slices <- Filter(function(x) x$id %in% filter_ids, snapshot_state) filtered_data$set_filter_state(slices) }, filtered_data = filtered_data_list, - filters = mapping_unfolded + filter_ids = mapping_unfolded ) slices_global(snapshot_state) removeModal() diff --git a/R/module_tabs_with_filters.R b/R/module_tabs_with_filters.R index 8d89921ef0..13fd6d5ebe 100644 --- a/R/module_tabs_with_filters.R +++ b/R/module_tabs_with_filters.R @@ -122,7 +122,7 @@ srv_tabs_with_filters <- function(id, ) if (!is_module_specific) { - active_datanames <- reactive(active_module()$filters) + active_datanames <- reactive(active_module()$datanames) singleton <- unlist(datasets)[[1]] singleton$srv_filter_panel("filter_panel", active_datanames = active_datanames) diff --git a/R/module_teal.R b/R/module_teal.R index 4250ae8878..de8279a911 100644 --- a/R/module_teal.R +++ b/R/module_teal.R @@ -182,20 +182,20 @@ srv_teal <- function(id, modules, raw_data, filter = teal_slices()) { names(datasets) <- labels datasets } else if (isTRUE(attr(filter, "module_specific"))) { - # we should create FilteredData even if modules$filter is null + # we should create FilteredData even if modules$datanames is null # null controls a display of filter panel but data should be still passed - datanames <- if (is.null(modules$filter)) raw_data()$get_datanames() else modules$filter + datanames <- if (is.null(modules$datanames)) raw_data()$get_datanames() else modules$datanames data_objects <- sapply( datanames, - simplify = FALSE, - FUN = function(dataname) { + function(dataname) { dataset <- raw_data()$get_dataset(dataname) list( dataset = dataset$get_raw_data(), metadata = dataset$get_metadata(), label = dataset$get_dataset_label() ) - } + }, + simplify = FALSE ) datasets_module <- teal.slice::init_filtered_data( data_objects, diff --git a/R/modules.R b/R/modules.R index d3ef4f0fcf..a80ac984c8 100644 --- a/R/modules.R +++ b/R/modules.R @@ -41,7 +41,7 @@ #' ns <- NS(id) #' tagList(dataTableOutput(ns("data"))) #' }, -#' filters = "all" +#' datanames = "all" #' ) #' ), #' module( @@ -58,7 +58,7 @@ #' ns <- NS(id) #' tagList(textOutput(ns("text"))) #' }, -#' filters = NULL +#' datanames = NULL #' ) #' ) #' ) @@ -145,10 +145,11 @@ is_arg_used <- function(modules, arg) { #' - `data` (optional) module will receive list of reactive (filtered) data specified in the `filters` argument. #' - `datasets` (optional) module will receive `FilteredData`. (See `[teal.slice::FilteredData]`). #' - `...` (optional) `ui_args` elements will be passed to the module named argument or to the `...`. -#' @param filters (`character`) A vector with `datanames` that are relevant for the item. The +#' @param filters (`character`) Deprecated. Use `datanames` instead. +#' @param datanames (`character`) A vector with `datanames` that are relevant for the item. The #' filter panel will automatically update the shown filters to include only #' filters in the listed datasets. `NULL` will hide the filter panel, -#' and the keyword `'all'` will show the filters of all datasets. `filters` determines also +#' and the keyword `'all'` will show filters of all datasets. `datanames` also determines #' a subset of datasets which are appended to the `data` argument in `server` function. #' @param server_args (named `list`) with additional arguments passed on to the #' `server` function. @@ -190,16 +191,26 @@ module <- function(label = "module", ui = function(id, ...) { tags$p(paste0("This module has no UI (id: ", id, " )")) }, - filters = "all", + filters, + datanames = "all", server_args = NULL, ui_args = NULL) { checkmate::assert_string(label) checkmate::assert_function(server) checkmate::assert_function(ui) - checkmate::assert_character(filters, min.len = 1, null.ok = TRUE, any.missing = FALSE) + checkmate::assert_character(datanames, min.len = 1, null.ok = TRUE, any.missing = FALSE) checkmate::assert_list(server_args, null.ok = TRUE, names = "named") checkmate::assert_list(ui_args, null.ok = TRUE, names = "named") + if (!missing(filters)) { + checkmate::assert_character(filters, min.len = 1, null.ok = TRUE, any.missing = FALSE) + datanames <- filters + msg <- + "The `filters` argument is deprecated and will be removed in the next release. Please use `datanames` instead." + logger::log_warn(msg) + warning(msg) + } + if (label == "global_filters") { stop("Label 'global_filters' is reserved in teal. Please change to something else.") } @@ -221,6 +232,11 @@ module <- function(label = "module", ) } + if (!is.element("data", server_formals)) { + message(sprintf("module \"%s\" server function takes no data so \"datanames\" will be ignored", label)) + datanames <- NULL + } + srv_extra_args <- setdiff(names(server_args), server_formals) if (length(srv_extra_args) > 0 && !"..." %in% server_formals) { stop( @@ -254,7 +270,7 @@ module <- function(label = "module", structure( list( label = label, - server = server, ui = ui, filters = filters, + server = server, ui = ui, datanames = datanames, server_args = server_args, ui_args = ui_args ), class = "teal_module" diff --git a/R/modules_debugging.R b/R/modules_debugging.R index 4213eba88e..6260f3908c 100644 --- a/R/modules_debugging.R +++ b/R/modules_debugging.R @@ -40,6 +40,6 @@ filter_calls_module <- function(label = "Filter Calls Module") { # nolint verbatimTextOutput(ns("filter_calls")) ) }, - filters = "all" + datanames = "all" ) } diff --git a/R/reporter_previewer_module.R b/R/reporter_previewer_module.R index 239ae70ec2..fd2411f76a 100644 --- a/R/reporter_previewer_module.R +++ b/R/reporter_previewer_module.R @@ -30,7 +30,7 @@ reporter_previewer_module <- function(label = "Report previewer", server_args = module <- module( label = label, server = srv, ui = ui, - server_args = server_args, ui_args = list(), filters = NULL + server_args = server_args, ui_args = list(), datanames = NULL ) class(module) <- c("teal_module_previewer", class(module)) module diff --git a/R/validations.R b/R/validations.R index 117eebb639..81e13554eb 100644 --- a/R/validations.R +++ b/R/validations.R @@ -284,16 +284,14 @@ validate_no_intersection <- function(x, y, msg) { #' } validate_has_variable <- function(data, varname, msg) { if (length(varname) != 0) { - has_vars <- all(varname %in% names(data)) - has_all <- all(has_vars) + has_vars <- varname %in% names(data) - if (!has_all) { + if (!all(has_vars)) { if (missing(msg)) { - dataname <- deparse(substitute(data)) - msg <- paste( - dataname, "does not have the required variables:", - paste(varname[!has_vars], collapse = ", "), - "." + msg <- sprintf( + "%s does not have the required variables: %s.", + deparse(substitute(data)), + toString(varname[!has_vars]) ) } validate(need(FALSE, msg)) diff --git a/inst/js/sidebar.js b/inst/js/sidebar.js index 9672f16c14..c3f8dddab8 100644 --- a/inst/js/sidebar.js +++ b/inst/js/sidebar.js @@ -5,7 +5,6 @@ const hideSidebar = () => { $(".teal_primary_col").attr("class", "teal_primary_col col-sm-12").resize(); }; const showSidebar = () => { - debugger; $(".teal_primary_col").attr("class", "teal_primary_col col-sm-9").resize(); $(".teal_secondary_col").delay(600).fadeIn(50); }; diff --git a/man/example_module.Rd b/man/example_module.Rd index 11b92b48ee..9a0c88862b 100644 --- a/man/example_module.Rd +++ b/man/example_module.Rd @@ -4,16 +4,16 @@ \alias{example_module} \title{An example \code{teal} module} \usage{ -example_module(label = "example teal module", filters = "all") +example_module(label = "example teal module", datanames = "all") } \arguments{ \item{label}{(\code{character(1)}) Label shown in the navigation item for the module. Any label possible except \code{"global_filters"} - read more in \code{mapping} argument of \link{teal_slices}.} -\item{filters}{(\code{character}) A vector with \code{datanames} that are relevant for the item. The +\item{datanames}{(\code{character}) A vector with \code{datanames} that are relevant for the item. The filter panel will automatically update the shown filters to include only filters in the listed datasets. \code{NULL} will hide the filter panel, -and the keyword \code{'all'} will show the filters of all datasets. \code{filters} determines also +and the keyword \code{'all'} will show filters of all datasets. \code{datanames} also determines a subset of datasets which are appended to the \code{data} argument in \code{server} function.} } \value{ diff --git a/man/init.Rd b/man/init.Rd index 2c28801aed..234f60697f 100644 --- a/man/init.Rd +++ b/man/init.Rd @@ -83,7 +83,7 @@ app <- init( label = "data source", server = function(input, output, session, data) {}, ui = function(id, ...) div(p("information about data source")), - filters = "all" + datanames = "all" ), example_module(label = "example teal module"), module( @@ -97,7 +97,7 @@ app <- init( ns <- NS(id) plotOutput(ns("hist")) }, - filters = "new_iris" + datanames = "new_iris" ) ), title = "App title", diff --git a/man/module.Rd b/man/module.Rd index f091f28d49..d7267630cd 100644 --- a/man/module.Rd +++ b/man/module.Rd @@ -17,7 +17,8 @@ module( tags$p(paste0("This module has no UI (id: ", id, " )")) }, - filters = "all", + filters, + datanames = "all", server_args = NULL, ui_args = NULL ) @@ -49,10 +50,12 @@ the \code{filters} argument. \item \code{...} (optional) \code{ui_args} elements will be passed to the module named argument or to the \code{...}. }} -\item{filters}{(\code{character}) A vector with \code{datanames} that are relevant for the item. The +\item{filters}{(\code{character}) Deprecated. Use \code{datanames} instead.} + +\item{datanames}{(\code{character}) A vector with \code{datanames} that are relevant for the item. The filter panel will automatically update the shown filters to include only filters in the listed datasets. \code{NULL} will hide the filter panel, -and the keyword \code{'all'} will show the filters of all datasets. \code{filters} determines also +and the keyword \code{'all'} will show filters of all datasets. \code{datanames} also determines a subset of datasets which are appended to the \code{data} argument in \code{server} function.} \item{server_args}{(named \code{list}) with additional arguments passed on to the diff --git a/man/modules.Rd b/man/modules.Rd index 9308058005..c86a83be06 100644 --- a/man/modules.Rd +++ b/man/modules.Rd @@ -65,7 +65,7 @@ app <- init( ns <- NS(id) tagList(dataTableOutput(ns("data"))) }, - filters = "all" + datanames = "all" ) ), module( @@ -82,7 +82,7 @@ app <- init( ns <- NS(id) tagList(textOutput(ns("text"))) }, - filters = NULL + datanames = NULL ) ) ) diff --git a/tests/testthat/test-module_nested_tabs.R b/tests/testthat/test-module_nested_tabs.R index fc8c560cd8..74aea0ecd8 100644 --- a/tests/testthat/test-module_nested_tabs.R +++ b/tests/testthat/test-module_nested_tabs.R @@ -6,26 +6,54 @@ test_module1 <- module( label = "test1", ui = function(id, ...) NULL, server = function(id) moduleServer(id, function(input, output, session) message("1")), - filters = NULL + datanames = NULL ) test_module2 <- module( label = "test2", ui = function(id) NULL, server = function(id) moduleServer(id, function(input, output, session) message("2")), - filters = NULL + datanames = NULL ) test_module3 <- module( label = "test3", ui = function(id) NULL, server = function(id) moduleServer(id, function(input, output, session) message("3")), - filters = NULL + datanames = NULL ) test_module4 <- module( label = "test4", ui = function(id) NULL, server = function(id) moduleServer(id, function(input, output, session) message("4")), - filters = NULL + datanames = NULL ) +test_module_wdata <- function(datanames) { + module( + label = "with_data", + ui = function(id) NULL, + server = function(id, data) moduleServer(id, function(input, output, session) message("module with data")), + datanames = datanames + ) +} + +get_example_filtered_data <- function() { + d1 <- data.frame(id = 1:5, pk = c(2, 3, 2, 1, 4), val = 1:5) + d2 <- data.frame(id = 1:5, value = 1:5) + + cc <- teal.data:::CodeClass$new() + cc$set_code("d1 <- data.frame(id = 1:5, pk = c(2,3,2,1,4), val = 1:5)", "d1") + cc$set_code("d2 <- data.frame(id = 1:5, value = 1:5)", "d2") + + teal.slice::init_filtered_data( + x = list( + d1 = list(dataset = d1, metadata = list("A" = 1)), + d2 = list(dataset = d2) + ), + join_keys = teal.data::join_keys(teal.data::join_key("d1", "d2", c("pk" = "id"))), + code = cc, + check = TRUE + ) +} + testthat::test_that("srv_nested_tabs throws error if reporter is not inherited from class Reporter", { testthat::expect_error( @@ -188,7 +216,7 @@ testthat::test_that("srv_nested_tabs.teal_module does pass data if in the args e server = function(id, data, ...) { moduleServer(id, function(input, output, session) checkmate::assert_class(data, "tdata")) }, - filters = NULL + datanames = NULL ) testthat::expect_no_error( shiny::testServer( @@ -207,7 +235,7 @@ testthat::test_that("srv_nested_tabs.teal_module does pass data if in the args e }) testthat::test_that("srv_nested_tabs.teal_module passes data to the server module", { - module <- module(filters = NULL, server = function(id, data) { + module <- module(datanames = NULL, server = function(id, data) { moduleServer(id, function(input, output, session) checkmate::assert_list(data, "reactive")) }) @@ -268,7 +296,7 @@ testthat::test_that("srv_nested_tabs.teal_module passes server_args to the ...", }) testthat::test_that("srv_nested_tabs.teal_module warns if both data and datasets are passed", { - module <- module(filters = NULL, label = "test module", server = function(id, datasets, data) { + module <- module(datanames = NULL, label = "test module", server = function(id, datasets, data) { moduleServer(id, function(input, output, session) NULL) }) @@ -360,25 +388,6 @@ testthat::test_that("srv_nested_tabs.teal_module passes filter_panel_api to the }) -get_example_filtered_data <- function() { - d1 <- data.frame(id = 1:5, pk = c(2, 3, 2, 1, 4), val = 1:5) - d2 <- data.frame(id = 1:5, value = 1:5) - - cc <- teal.data:::CodeClass$new() - cc$set_code("d1 <- data.frame(id = 1:5, pk = c(2,3,2,1,4), val = 1:5)", "d1") - cc$set_code("d2 <- data.frame(id = 1:5, value = 1:5)", "d2") - - teal.slice::init_filtered_data( - x = list( - d1 = list(dataset = d1, metadata = list("A" = 1)), - d2 = list(dataset = d2) - ), - join_keys = teal.data::join_keys(teal.data::join_key("d1", "d2", c("pk" = "id"))), - code = cc, - check = TRUE - ) -} - testthat::test_that(".datasets_to_data accepts a reactiveVal as trigger_data input", { datasets <- get_example_filtered_data() datasets$set_filter_state( @@ -386,7 +395,7 @@ testthat::test_that(".datasets_to_data accepts a reactiveVal as trigger_data inp teal.slice:::teal_slice(dataname = "d1", varname = "val", selected = c(1, 2)) ) ) - module <- list(filter = c("d1", "d2")) + module <- test_module_wdata(datanames = c("d1", "d2")) trigger_data <- reactiveVal(1L) testthat::expect_silent(shiny::isolate(.datasets_to_data(module, datasets, trigger_data))) }) @@ -398,7 +407,7 @@ testthat::test_that(".datasets_to_data throws error if trigger_data is not a rea teal.slice:::teal_slice(dataname = "d1", varname = "val", selected = c(1, 2)) ) ) - module <- list(filter = "all") + module <- test_module_wdata(datanames = "all") trigger_data <- 1 testthat::expect_error( shiny::isolate(.datasets_to_data(module, datasets, trigger_data)), @@ -413,7 +422,7 @@ testthat::test_that(".datasets_to_data returns data which is filtered", { teal.slice:::teal_slice(dataname = "d1", varname = "val", selected = c(1, 2)) ) ) - module <- list(filter = c("d1", "d2")) + module <- test_module_wdata(datanames = c("d1", "d2")) trigger_data <- reactiveVal(1L) data <- shiny::isolate(.datasets_to_data(module, datasets, trigger_data)) @@ -424,9 +433,9 @@ testthat::test_that(".datasets_to_data returns data which is filtered", { }) -testthat::test_that(".datasets_to_data returns only data requested by modules$filter", { +testthat::test_that(".datasets_to_data returns only data requested by modules$datanames", { datasets <- get_example_filtered_data() - module <- list(filter = "d1") + module <- test_module_wdata(datanames = "d1") trigger_data <- reactiveVal(1L) data <- .datasets_to_data(module, datasets, trigger_data) testthat::expect_equal(shiny::isolate(names(data)), "d1") @@ -434,7 +443,7 @@ testthat::test_that(".datasets_to_data returns only data requested by modules$fi testthat::test_that(".datasets_to_data returns tdata object", { datasets <- get_example_filtered_data() - module <- list(filter = c("d1", "d2")) + module <- test_module_wdata(datanames = c("d1", "d2")) trigger_data <- reactiveVal(1L) data <- .datasets_to_data(module, datasets, trigger_data) diff --git a/tests/testthat/test-module_tabs_with_filters.R b/tests/testthat/test-module_tabs_with_filters.R index b65c0a56f8..a82042cc81 100644 --- a/tests/testthat/test-module_tabs_with_filters.R +++ b/tests/testthat/test-module_tabs_with_filters.R @@ -7,11 +7,19 @@ filtered_data <- teal.slice::init_filtered_data( test_module1 <- module( label = "iris tab", - filters = "iris" + server = function(id, data, ...) { + moduleServer(id, function(input, output, session) { + }) + }, + datanames = "iris" ) test_module2 <- module( label = "mtcars tab", - filters = "mtcars" + server = function(id, data, ...) { + moduleServer(id, function(input, output, session) { + }) + }, + datanames = "mtcars" ) testthat::test_that("srv_tabs_with_filters throws error if reporter is not of class Reporter", { diff --git a/tests/testthat/test-module_teal.R b/tests/testthat/test-module_teal.R index b6562d0f23..fddc04b2c7 100644 --- a/tests/testthat/test-module_teal.R +++ b/tests/testthat/test-module_teal.R @@ -4,11 +4,11 @@ data <- teal_data(iris_ds, mtcars_ds) test_module1 <- module( label = "iris_tab", - filters = "iris" + datanames = "iris" ) test_module2 <- module( label = "mtcars_tab", - filters = "mtcars" + datanames = "mtcars" ) testthat::test_that("srv_teal fails when raw_data is not reactive", { diff --git a/tests/testthat/test-module_teal_with_splash.R b/tests/testthat/test-module_teal_with_splash.R index e77e889b12..f96d13633a 100644 --- a/tests/testthat/test-module_teal_with_splash.R +++ b/tests/testthat/test-module_teal_with_splash.R @@ -4,7 +4,7 @@ data <- teal_data(iris_ds, mtcars_ds) test_module1 <- module( label = "iris_tab", - filters = "iris" + datanames = "iris" ) testthat::test_that("srv_teal_with_splash creates reactiveVal returning data input", { diff --git a/tests/testthat/test-modules.R b/tests/testthat/test-modules.R index 88b9b9f8fa..dc2fd11c49 100644 --- a/tests/testthat/test-modules.R +++ b/tests/testthat/test-modules.R @@ -5,7 +5,7 @@ adsl_dataset <- teal.data::cdisc_dataset( parent = character(0), keys = teal.data::get_cdisc_keys("ADSL") ) -call_module_server_fun <- function(input, output, session, datasets) { +call_module_server_fun <- function(input, output, session, data, datasets) { } module_server_fun <- function(id, datasets) { @@ -20,11 +20,11 @@ ui_fun2 <- function(id, datasets) { } testthat::test_that("Calling module() does not throw", { - testthat::expect_error(module(), NA) + testthat::expect_no_error(suppressMessages(module())) }) testthat::test_that("module requires label argument to be a string different than 'global_filters'", { - testthat::expect_error(module(label = "label"), NA) + testthat::expect_no_error(module(label = "label")) testthat::expect_error(module(label = NULL), "Assertion on 'label' failed.+'NULL'") @@ -36,17 +36,11 @@ testthat::test_that("module requires label argument to be a string different tha }) testthat::test_that("module expects server being a shiny server module with any argument", { - testthat::expect_error(module( - server = function(id) NULL - ), NA) + testthat::expect_no_error(module(server = function(id) NULL)) - testthat::expect_error(module( - server = function(id, any_argument) NULL, - ), NA) + testthat::expect_no_error(module(server = function(id, any_argument) NULL)) - testthat::expect_error(module( - server = function(input, output, session, any_argument) NULL, - ), NA) + testthat::expect_no_error(module(server = function(input, output, session, any_argument) NULL)) testthat::expect_error( @@ -61,23 +55,17 @@ testthat::test_that("module expects server being a shiny server module with any }) testthat::test_that("module requires server_args argument to be a list", { - testthat::expect_error(module(server = function(id, a) NULL, server_args = list(a = 1)), NA) - testthat::expect_error(module(server_args = list()), NA) - testthat::expect_error(module(server_args = NULL), NA) + testthat::expect_no_error(module(server = function(id, a) NULL, server_args = list(a = 1))) + testthat::expect_no_error(module(server_args = list())) + testthat::expect_no_error(module(server_args = NULL)) testthat::expect_error(module(server_args = ""), "Assertion on 'server_args' failed.+'list'") testthat::expect_error(module(server_args = list(1, 2, 3)), "Must have names") }) testthat::test_that("module expects all server_args being a server arguments or passed through `...`", { - testthat::expect_error(module( - server = function(id, arg1) NULL, - server_args = list(arg1 = NULL) - ), NA) + testthat::expect_no_error(module(server = function(id, arg1) NULL, server_args = list(arg1 = NULL))) - testthat::expect_error(module( - server = function(id, ...) NULL, - server_args = list(arg1 = NULL) - ), NA) + testthat::expect_no_error(module(server = function(id, ...) NULL, server_args = list(arg1 = NULL))) testthat::expect_error( module(server = function(id) NULL, server_args = list(arg1 = NULL)), @@ -86,16 +74,16 @@ testthat::test_that("module expects all server_args being a server arguments or }) testthat::test_that("module requires ui_args argument to be a list", { - testthat::expect_error(module(ui = function(id, a) NULL, ui_args = list(a = 1)), NA) - testthat::expect_error(module(ui_args = list()), NA) - testthat::expect_error(module(ui_args = NULL), NA) + testthat::expect_no_error(module(ui = function(id, a) NULL, ui_args = list(a = 1))) + testthat::expect_no_error(module(ui_args = list())) + testthat::expect_no_error(module(ui_args = NULL)) testthat::expect_error(module(ui_args = ""), "Assertion on 'ui_args' failed.+'list'") testthat::expect_error(module(ui_args = list(1, 2, 3)), "Must have names") }) testthat::test_that("module expects ui being a shiny ui module with any argument", { - testthat::expect_error(module(ui = function(id) NULL), NA) - testthat::expect_error(module(ui = function(id, any_argument) NULL), NA) + testthat::expect_no_error(module(ui = function(id) NULL)) + testthat::expect_no_error(module(ui = function(id, any_argument) NULL)) testthat::expect_error( module(ui = function(any_argument) NULL), "`ui` argument requires a function with following arguments" @@ -103,16 +91,9 @@ testthat::test_that("module expects ui being a shiny ui module with any argument }) testthat::test_that("module expects all ui_args being a ui arguments or passed through `...`", { - testthat::expect_error(module( - ui = function(id, arg1) NULL, - ui_args = list(arg1 = NULL) - ), NA) - - testthat::expect_error(module( - ui = function(id, ...) NULL, - ui_args = list(arg1 = NULL) - ), NA) + testthat::expect_no_error(module(ui = function(id, arg1) NULL, ui_args = list(arg1 = NULL))) + testthat::expect_no_error(module(ui = function(id, ...) NULL, ui_args = list(arg1 = NULL))) testthat::expect_error( module(ui = function(id) NULL, ui_args = list(arg1 = NULL)), @@ -120,12 +101,12 @@ testthat::test_that("module expects all ui_args being a ui arguments or passed t ) }) -testthat::test_that("module requires filters argument to be a character or NULL", { - testthat::expect_error(module(filters = "all"), NA) - testthat::expect_error(module(filters = ""), NA) - testthat::expect_error(module(filters = NULL), NA) - testthat::expect_error(module(filters = NA_character_), "Contains missing values") - testthat::expect_error(module(server = function(id, data) NULL, filters = NULL), NA) +testthat::test_that("module requires datanames argument to be a character or NULL", { + testthat::expect_no_error(module(datanames = "all")) + testthat::expect_no_error(module(datanames = "")) + testthat::expect_no_error(module(datanames = NULL)) + testthat::expect_error(module(datanames = NA_character_), "Contains missing values") + testthat::expect_no_error(module(server = function(id, data) NULL, datanames = NULL)) }) testthat::test_that("module() returns list of class 'teal_module' containing input objects", { @@ -133,16 +114,16 @@ testthat::test_that("module() returns list of class 'teal_module' containing inp label = "aaa1", server = call_module_server_fun, ui = ui_fun1, - filters = "all", + datanames = "all", server_args = NULL, ui_args = NULL ) testthat::expect_s3_class(test_module, "teal_module") - testthat::expect_named(test_module, c("label", "server", "ui", "filters", "server_args", "ui_args")) + testthat::expect_named(test_module, c("label", "server", "ui", "datanames", "server_args", "ui_args")) testthat::expect_identical(test_module$label, "aaa1") testthat::expect_identical(test_module$server, call_module_server_fun) testthat::expect_identical(test_module$ui, ui_fun1) - testthat::expect_identical(test_module$filters, "all") + testthat::expect_identical(test_module$datanames, "all") testthat::expect_identical(test_module$server_args, NULL) testthat::expect_identical(test_module$ui_args, NULL) }) @@ -157,10 +138,10 @@ testthat::test_that("modules requires label argument to be a string ", { label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) - testthat::expect_error(modules(label = "label", test_module), NA) + testthat::expect_no_error(modules(label = "label", test_module)) testthat::expect_error(modules(label = NULL, test_module), "Assertion on 'label' failed.+'NULL'") testthat::expect_error( modules(label = c("label", "label"), test_module), @@ -173,10 +154,10 @@ testthat::test_that("modules accept teal_module in ...", { label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) - testthat::expect_error(modules(label = "label", test_module), NA) + testthat::expect_no_error(modules(label = "label", test_module)) }) testthat::test_that("modules accept multiple teal_module objects in ...", { @@ -184,10 +165,10 @@ testthat::test_that("modules accept multiple teal_module objects in ...", { label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) - testthat::expect_error(modules(label = "label", test_module, test_module), NA) + testthat::expect_no_error(modules(label = "label", test_module, test_module)) }) testthat::test_that("modules accept multiple teal_module and teal_modules objects in ...", { @@ -195,11 +176,11 @@ testthat::test_that("modules accept multiple teal_module and teal_modules object label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) test_modules <- modules(label = "label", test_module) - testthat::expect_error(modules(label = "label", test_module, test_modules), NA) + testthat::expect_no_error(modules(label = "label", test_module, test_modules)) }) testthat::test_that("modules does not accept objects other than teal_module(s) in ...", { @@ -221,7 +202,7 @@ testthat::test_that("modules returns teal_modules object with label and children label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) out <- modules(label = "label2", test_module) testthat::expect_s3_class(out, "teal_modules") @@ -233,7 +214,7 @@ testthat::test_that("modules returns children as list with list named after labe label = "module", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) test_modules <- modules(label = "modules", test_module) out <- modules(label = "tabs", test_module, test_modules)$children @@ -248,9 +229,12 @@ testthat::test_that("modules returns useful error message if label argument not label = "module", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" + ) + testthat::expect_error( + modules("module", test_module), + "The only character argument to modules\\(\\) must be 'label'" ) - testthat::expect_error(modules("module", test_module), "The only character argument to modules\\(\\) must be 'label'") }) @@ -259,7 +243,7 @@ testthat::test_that("modules returns children as list with unique names if label label = "module", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) test_modules <- modules(label = "module", test_module) out <- modules(label = "tabs", test_module, test_modules)$children @@ -270,17 +254,16 @@ testthat::test_that("modules returns children as list with unique names if label testthat::test_that("modules_depth accepts depth as integer", { - testthat::expect_error( + testthat::expect_no_error( modules_depth( module( label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ), depth = 3L - ), - NA + ) ) testthat::expect_error( @@ -289,7 +272,7 @@ testthat::test_that("modules_depth accepts depth as integer", { label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ), depth = "1" ), @@ -304,7 +287,7 @@ testthat::test_that("modules_depth returns depth=0 by default", { label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) ), 0L @@ -312,18 +295,17 @@ testthat::test_that("modules_depth returns depth=0 by default", { }) testthat::test_that("modules_depth accepts modules to be teal_module or teal_modules", { - testthat::expect_error( + testthat::expect_no_error( modules_depth( module( label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) - ), - NA + ) ) - testthat::expect_error( + testthat::expect_no_error( modules_depth( modules( label = "tabs", @@ -331,11 +313,10 @@ testthat::test_that("modules_depth accepts modules to be teal_module or teal_mod label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) ) - ), - NA + ) ) }) @@ -346,7 +327,7 @@ testthat::test_that("modules_depth returns depth same as input for teal_module", label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) ), 0L @@ -362,7 +343,7 @@ testthat::test_that("modules_depth increases depth by 1 for each teal_modules", label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) ), depth = 1L @@ -380,7 +361,7 @@ testthat::test_that("modules_depth increases depth by 1 for each teal_modules", label = "label", server = module_server_fun, ui = ui_fun1, - filters = "" + datanames = "" ) ) ), diff --git a/vignettes/adding-support-for-reporting.Rmd b/vignettes/adding-support-for-reporting.Rmd index cb936d1040..f8b11369b4 100644 --- a/vignettes/adding-support-for-reporting.Rmd +++ b/vignettes/adding-support-for-reporting.Rmd @@ -46,7 +46,7 @@ teal_example_module <- function(label = "example teal module") { encoding = selectInput(ns("dataname"), "Choose a dataset", choices = names(data)) ) }, - filters = "all" + datanames = "all" ) } ``` @@ -89,7 +89,7 @@ example_module_with_reporting <- function(label = "example teal module") { encoding = selectInput(ns("dataname"), "Choose a dataset", choices = names(data)) ) }, - filters = "all" + datanames = "all" ) } ``` @@ -140,7 +140,7 @@ example_module_with_reporting <- function(label = "example teal module") { encoding = selectInput(ns("dataname"), "Choose a dataset", choices = names(data)) ) }, - filters = "all" + datanames = "all" ) } ``` @@ -195,7 +195,7 @@ example_module_with_reporting <- function(label = "example teal module") { encoding = selectInput(ns("dataname"), "Choose a dataset", choices = names(data)) ) }, - filters = "all" + datanames = "all" ) } ``` @@ -318,7 +318,7 @@ example_reporter_module <- function(label = "Example") { ) ) }, - filters = "all" + datanames = "all" ) } diff --git a/vignettes/creating-custom-modules.Rmd b/vignettes/creating-custom-modules.Rmd index a5768e1c53..6d5e9fea93 100644 --- a/vignettes/creating-custom-modules.Rmd +++ b/vignettes/creating-custom-modules.Rmd @@ -35,7 +35,7 @@ example_module <- function(label = "example teal module") { encoding = selectInput(ns("dataname"), "Choose a dataset", choices = names(data)) ) }, - filters = "all" + datanames = "all" ) } ``` @@ -170,7 +170,7 @@ tm_histogram_example <- function(label, histogram_var) { ui = ui_histogram_example, ui_args = list(histogram_var = histogram_var), server_args = list(histogram_var = histogram_var), - filters = "all" + datanames = "all" ) } ``` diff --git a/vignettes/filter-panel.Rmd b/vignettes/filter-panel.Rmd index 345a2bed5c..6c20beba5f 100644 --- a/vignettes/filter-panel.Rmd +++ b/vignettes/filter-panel.Rmd @@ -57,9 +57,9 @@ app <- init( ), modules = modules( example_module(label = "all datasets"), - example_module(label = "IRIS only", filters = "IRIS"), - example_module(label = "CARS only", filters = "CARS"), - example_module(label = "no filter panel", filters = NULL) + example_module(label = "IRIS only", datanames = "IRIS"), + example_module(label = "CARS only", datanames = "CARS"), + example_module(label = "no filter panel", datanames = NULL) ) ) if (interactive()) {