From 1c75925e5a564d5a672d2ccdcb782fe3b0c76451 Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Wed, 30 Oct 2024 13:25:31 +0100 Subject: [PATCH] post merge fixes --- NAMESPACE | 4 +- R/dummy_functions.R | 4 +- R/init.R | 2 +- R/module_nested_tabs.R | 31 ++++++-------- R/module_teal.R | 2 +- R/module_teal_data.R | 22 +++++----- R/module_transform_data.R | 32 +++++++-------- R/modules.R | 32 +++++++-------- R/teal_transform_module.R | 20 ++++----- man/example_module.Rd | 11 ++--- ..._transformers.Rd => extract_transforms.Rd} | 10 ++--- man/module_teal.Rd | 2 +- man/module_teal_data.Rd | 6 +-- man/module_teal_transform_module.Rd | 40 ------------------ man/module_transform_data.Rd | 41 +++++++++++++++++++ man/teal_modules.Rd | 21 +++++----- man/teal_transform_module.Rd | 24 +++++------ 17 files changed, 150 insertions(+), 154 deletions(-) rename man/{extract_transformers.Rd => extract_transforms.Rd} (61%) delete mode 100644 man/module_teal_transform_module.Rd create mode 100644 man/module_transform_data.Rd diff --git a/NAMESPACE b/NAMESPACE index 224c65d040..e2535df1aa 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,15 +31,15 @@ export(reporter_previewer_module) export(set_datanames) export(show_rcode_modal) export(srv_teal) -export(srv_teal_transform_module) export(srv_teal_with_splash) +export(srv_transform_data) export(tdata2env) export(teal_data_module) export(teal_slices) export(teal_transform_module) export(ui_teal) -export(ui_teal_transform_module) export(ui_teal_with_splash) +export(ui_transform_data) export(validate_has_data) export(validate_has_elements) export(validate_has_variable) diff --git a/R/dummy_functions.R b/R/dummy_functions.R index fd3f067699..ed76b5aa55 100644 --- a/R/dummy_functions.R +++ b/R/dummy_functions.R @@ -13,7 +13,7 @@ #' shinyApp(app$ui, app$server) #' } #' @export -example_module <- function(label = "example teal module", datanames = "all", transformers = list()) { +example_module <- function(label = "example teal module", datanames = "all", transforms = list()) { checkmate::assert_string(label) ans <- module( label, @@ -59,7 +59,7 @@ example_module <- function(label = "example teal module", datanames = "all", tra ) }, datanames = datanames, - transformers = transformers + transforms = transforms ) attr(ans, "teal_bookmarkable") <- TRUE ans diff --git a/R/init.R b/R/init.R index a62034eaf8..eddb9e6d19 100644 --- a/R/init.R +++ b/R/init.R @@ -212,7 +212,7 @@ init <- function(data, } is_modules_ok <- check_modules_datanames(modules, ls(teal.code::get_env(data))) - if (!isTRUE(is_modules_ok) && length(unlist(extract_transformers(modules))) == 0) { + if (!isTRUE(is_modules_ok) && length(unlist(extract_transforms(modules))) == 0) { lapply(is_modules_ok$string, warning, call. = FALSE) } diff --git a/R/module_nested_tabs.R b/R/module_nested_tabs.R index 02f5738529..15afe4b854 100644 --- a/R/module_nested_tabs.R +++ b/R/module_nested_tabs.R @@ -94,11 +94,11 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) { ui_teal <- tagList( shinyjs::hidden( tags$div( - id = ns("transformer_failure_info"), + id = ns("transform_failure_info"), class = "teal_validated", div( class = "teal-output-warning", - "One of transformers failed. Please fix and continue." + "One of transforms failed. Please fix and continue." ) ) ), @@ -125,10 +125,7 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) { width = 3, ui_data_summary(ns("data_summary")), ui_filter_data(ns("filter_panel")), - if (length(modules$transformers) > 0 && !isTRUE(attr(modules$transformers, "custom_ui"))) { - ui_teal_transform_module(ns("data_transform"), transforms = modules$transformers, class = "well") - }, - ui_transform_data(ns("data_transform"), transformers = modules$transformers, class = "well"), + ui_transform_data(ns("data_transform"), transforms = modules$transforms, class = "well"), class = "teal_secondary_col" ) ) @@ -263,27 +260,25 @@ srv_teal_module.teal_module <- function(id, data_rv = data_rv, is_active = is_active ) - is_transformer_failed <- reactiveValues() + is_transform_failed <- reactiveValues() transformed_teal_data <- srv_transform_data( "data_transform", data = filtered_teal_data, - transformers = modules$transformers, + transforms = modules$transforms, modules = modules, - is_transformer_failed = is_transformer_failed + is_transform_failed = is_transform_failed ) - any_transformer_failed <- reactive({ - any(unlist(reactiveValuesToList(is_transformer_failed))) + any_transform_failed <- reactive({ + any(unlist(reactiveValuesToList(is_transform_failed))) }) - observeEvent(any_transformer_failed(), { - if (isTRUE(any_transformer_failed())) { + observeEvent(any_transform_failed(), { + if (isTRUE(any_transform_failed())) { shinyjs::hide("teal_module_ui") - shinyjs::hide("validate_datanames") - shinyjs::show("transformer_failure_info") + shinyjs::show("transform_failure_info") } else { shinyjs::show("teal_module_ui") - shinyjs::show("validate_datanames") - shinyjs::hide("transformer_failure_info") + shinyjs::hide("transform_failure_info") } }) @@ -294,7 +289,7 @@ srv_teal_module.teal_module <- function(id, .subset_teal_data(all_teal_data, module_datanames) }) - srv_validate_reactive_teal_data( + srv_check_module_datanames( "validate_datanames", data = module_teal_data, modules = modules diff --git a/R/module_teal.R b/R/module_teal.R index e9e6b82f7e..478e816e91 100644 --- a/R/module_teal.R +++ b/R/module_teal.R @@ -20,7 +20,7 @@ #' performed: #' - data loading in [`module_init_data`] #' - data filtering in [`module_filter_data`] -#' - data transformation in [`module_teal_transform_module`] +#' - data transformation in [`module_transform_data`] #' #' ## Fallback on failure #' diff --git a/R/module_teal_data.R b/R/module_teal_data.R index 91294f3c17..3ea560ee4d 100644 --- a/R/module_teal_data.R +++ b/R/module_teal_data.R @@ -25,8 +25,8 @@ #' @param data_module (`teal_data_module`) #' @param modules (`teal_modules` or `teal_module`) For `datanames` validation purpose #' @param validate_shiny_silent_error (`logical`) If `TRUE`, then `shiny.silent.error` is validated and -#' @param is_transformer_failed (`reactiveValues`) contains `logical` flags named after each transformer. -#' Help to determine if any previous transformer failed, so that following transformers can be disabled +#' @param is_transform_failed (`reactiveValues`) contains `logical` flags named after each transform. +#' Help to determine if any previous transform failed, so that following transforms can be disabled #' and display a generic failure message. #' #' @return `reactive` `teal_data` @@ -53,29 +53,29 @@ srv_teal_data <- function(id, data_module = function(id) NULL, modules = NULL, validate_shiny_silent_error = TRUE, - is_transformer_failed = reactiveValues()) { + is_transform_failed = reactiveValues()) { checkmate::assert_string(id) checkmate::assert_function(data_module, args = "id") checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"), null.ok = TRUE) - checkmate::assert_class(is_transformer_failed, "reactivevalues") + checkmate::assert_class(is_transform_failed, "reactivevalues") moduleServer(id, function(input, output, session) { logger::log_debug("srv_teal_data initializing.") - is_transformer_failed[[id]] <- FALSE + is_transform_failed[[id]] <- FALSE data_out <- data_module(id = "data") data_handled <- reactive(tryCatch(data_out(), error = function(e) e)) observeEvent(data_handled(), { if (!inherits(data_handled(), "teal_data")) { - is_transformer_failed[[id]] <- TRUE + is_transform_failed[[id]] <- TRUE } else { - is_transformer_failed[[id]] <- FALSE + is_transform_failed[[id]] <- FALSE } }) is_previous_failed <- reactive({ - idx_this <- which(names(is_transformer_failed) == id) - is_transformer_failed_list <- reactiveValuesToList(is_transformer_failed) - idx_failures <- which(unlist(is_transformer_failed_list)) + idx_this <- which(names(is_transform_failed) == id) + is_transform_failed_list <- reactiveValuesToList(is_transform_failed) + idx_failures <- which(unlist(is_transform_failed_list)) any(idx_failures < idx_this) }) @@ -133,7 +133,7 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length output$previous_failed <- renderUI({ if (hide_validation_error()) { shinyjs::hide("validate_messages") - tags$div("One of previous transformers failed. Please fix and continue.", class = "teal-output-warning") + tags$div("One of previous transforms failed. Please fix and continue.", class = "teal-output-warning") } else { shinyjs::show("validate_messages") NULL diff --git a/R/module_transform_data.R b/R/module_transform_data.R index 6b9e04f6b8..1fd7e52211 100644 --- a/R/module_transform_data.R +++ b/R/module_transform_data.R @@ -8,12 +8,12 @@ #' @return `reactive` `teal_data` #' #' -#' @name module_teal_transform_module +#' @name module_transform_data NULL #' @export -#' @rdname module_teal_transform_module -ui_teal_transform_module <- function(id, transforms, class = "well") { +#' @rdname module_transform_data +ui_transform_data <- function(id, transforms, class = "well") { checkmate::assert_string(id) if (length(transforms) == 0L) { return(NULL) @@ -25,10 +25,10 @@ ui_teal_transform_module <- function(id, transforms, class = "well") { labels <- lapply(transforms, function(x) attr(x, "label")) ids <- get_unique_labels(labels) - names(transformers) <- ids + names(transforms) <- ids lapply( - names(transformers), + names(transforms), function(name) { child_id <- NS(id)(name) ns <- NS(child_id) @@ -70,8 +70,8 @@ ui_teal_transform_module <- function(id, transforms, class = "well") { } #' @export -#' @rdname module_teal_transform_module -srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_transformer_failed = reactiveValues()) { +#' @rdname module_transform_data +srv_transform_data <- function(id, data, transforms, modules = NULL, is_transform_failed = reactiveValues()) { checkmate::assert_string(id) assert_reactive(data) checkmate::assert_class(modules, "teal_module", null.ok = TRUE) @@ -90,22 +90,22 @@ srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_t Reduce( function(data_previous, name) { moduleServer(name, function(input, output, session) { - logger::log_debug("srv_teal_transform_module initializing for { name }.") - is_transformer_failed[[name]] <- FALSE + logger::log_debug("srv_transform_data initializing for { name }.") + is_transform_failed[[name]] <- FALSE data_out <- transforms[[name]]$server(name, data = data_previous) data_handled <- reactive(tryCatch(data_out(), error = function(e) e)) observeEvent(data_handled(), { if (inherits(data_handled(), "teal_data")) { - is_transformer_failed[[name]] <- FALSE + is_transform_failed[[name]] <- FALSE } else { - is_transformer_failed[[name]] <- TRUE + is_transform_failed[[name]] <- TRUE } }) is_previous_failed <- reactive({ - idx_this <- which(names(is_transformer_failed) == name) - is_transformer_failed_list <- reactiveValuesToList(is_transformer_failed) - idx_failures <- which(unlist(is_transformer_failed_list)) + idx_this <- which(names(is_transform_failed) == name) + is_transform_failed_list <- reactiveValuesToList(is_transform_failed) + idx_failures <- which(unlist(is_transform_failed_list)) any(idx_failures < idx_this) }) @@ -119,7 +119,7 @@ srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_t output$error_wrapper <- renderUI({ if (is_previous_failed()) { shinyjs::disable(transform_wrapper_id) - tags$div("One of previous transformers failed. Please fix and continue.", class = "teal-output-warning") + tags$div("One of previous transforms failed. Please fix and continue.", class = "teal-output-warning") } else { shinyjs::enable(transform_wrapper_id) shiny::tagList( @@ -133,7 +133,7 @@ srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_t .trigger_on_success(data_handled) }) }, - x = names(transformers), + x = names(transforms), init = data ) }) diff --git a/R/modules.R b/R/modules.R index fc270e5f54..15d2c13caa 100644 --- a/R/modules.R +++ b/R/modules.R @@ -35,12 +35,12 @@ setOldClass("teal_modules") #' in a warning. Datasets with names starting with . are ignored globally unless explicitly listed #' in `datanames`. #' -#' # `datanames` with `transformers` -#' When transformers are specified, their `datanames` are added to the module’s `datanames`, which +#' # `datanames` with `transforms` +#' When transforms are specified, their `datanames` are added to the module’s `datanames`, which #' changes the behavior as follows: -#' - If `module(datanames)` is `NULL` and the `transformers` have defined `datanames`, the sidebar -#' will appear showing the `transformers`' datasets, instead of being hidden. -#' - If `module(datanames)` is set to specific values and any `transformer` has `datanames = "all"`, +#' - If `module(datanames)` is `NULL` and the `transforms` have defined `datanames`, the sidebar +#' will appear showing the `transforms`' datasets, instead of being hidden. +#' - If `module(datanames)` is set to specific values and any `transform` has `datanames = "all"`, #' the module may receive extra datasets that could be unnecessary #' #' @param label (`character(1)`) Label shown in the navigation item for the module or module group. @@ -69,14 +69,14 @@ setOldClass("teal_modules") #' There are 2 reserved values that have specific behaviors: #' - The keyword `"all"` includes all datasets available in the data passed to the teal application. #' - `NULL` hides the sidebar panel completely. -#' - If `transformers` are specified, their `datanames` are automatically added to this `datanames` +#' - If `transforms` are specified, their `datanames` are automatically added to this `datanames` #' argument. #' @param server_args (named `list`) with additional arguments passed on to the server function. #' @param ui_args (named `list`) with additional arguments passed on to the UI function. #' @param x (`teal_module` or `teal_modules`) Object to format/print. -#' @param transformers (`list` of `teal_transform_module`) that will be applied to transform module's data input. +#' @param transforms (`list` of `teal_transform_module`) that will be applied to transform module's data input. #' Each transform module UI will appear in the `teal` application, unless the `custom_ui` attribute is set on the list. -#' If so, the module developer is responsible to display the UI in the module itself. `datanames` of the `transformers` +#' If so, the module developer is responsible to display the UI in the module itself. `datanames` of the `transforms` #' will be added to the `datanames`. #' #' @@ -159,7 +159,7 @@ module <- function(label = "module", datanames = "all", server_args = NULL, ui_args = NULL, - transformers = list()) { + transforms = list()) { # argument checking (independent) ## `label` checkmate::assert_string(label) @@ -266,16 +266,16 @@ module <- function(label = "module", ) } - ## `transformers` - if (inherits(transformers, "teal_transform_module")) { - transformers <- list(transformers) + ## `transforms` + if (inherits(transforms, "teal_transform_module")) { + transforms <- list(transforms) } - checkmate::assert_list(transformers, types = "teal_transform_module") - transformer_datanames <- unlist(lapply(transformers, attr, "datanames")) + checkmate::assert_list(transforms, types = "teal_transform_module") + transform_datanames <- unlist(lapply(transforms, attr, "datanames")) combined_datanames <- if (identical(datanames, "all")) { "all" } else { - union(datanames, transformer_datanames) + union(datanames, transform_datanames) } structure( @@ -286,7 +286,7 @@ module <- function(label = "module", datanames = combined_datanames, server_args = server_args, ui_args = ui_args, - transformers = transformers + transforms = transforms ), class = "teal_module" ) diff --git a/R/teal_transform_module.R b/R/teal_transform_module.R index 9596d6df7a..9c1b0f8504 100644 --- a/R/teal_transform_module.R +++ b/R/teal_transform_module.R @@ -1,4 +1,4 @@ -#' Data module for `teal` transformers. +#' Data module for `teal` transforms. #' #' @description #' `r lifecycle::badge("experimental")` @@ -18,14 +18,14 @@ #' `teal_transform_module`'s purpose is to modify any object created in [`teal.data::teal_data`]. It means that an #' app-developer can use `teal_transform_module` to modify data but also outputted tables, listings and graphs. #' Some [`teal_modules`] enables app developer to inject custom shiny module to modify displayed output. -#' To handle these `decorators` inside of your module use [ui_teal_transform_module()] and [srv_teal_transform_module]. +#' To handle these `decorators` inside of your module use [ui_transform_data()] and [srv_transform_data]. #' (todo: write more about how to handle decorators: they need to go through ui_args/srv_args and then be consumed by -#' ui/srv_teal_transform_module()... . Alternatively, decorators could be a [module()]'s argument) +#' ui/srv_transform_data()... . Alternatively, decorators could be a [module()]'s argument) #' #' # `server` as a language #' #' Server function in `teal_transform_module` must return `reactive` containing [teal.data::teal_data] object. -#' Consider sinmple transformer which doesn't require any advanced reactivity, example `server` might have a +#' Consider sinmple transform which doesn't require any advanced reactivity, example `server` might have a #' following form: #' #' ``` @@ -46,7 +46,7 @@ #' respective input matched by its name. #' #' ``` -#' make_teal_transform_module(expr = expression(x <- subset(x, col == level))) +#' make_transform_data(expr = expression(x <- subset(x, col == level))) #' ``` #' @inheritParams teal_data_module #' @param server (`function(id, data)` or `language`) @@ -61,7 +61,7 @@ #' #' #' @examples -#' my_transformers <- list( +#' my_transforms <- list( #' teal_transform_module( #' label = "Static transform for iris", #' datanames = "iris", @@ -165,15 +165,15 @@ make_teal_transform_server <- function(expr) { } } -#' Extract all `transformers` from `modules`. +#' Extract all `transforms` from `modules`. #' #' @param modules `teal_modules` or `teal_module` #' @return A list of `teal_transform_module` nested in the same way as input `modules`. #' @keywords internal -extract_transformers <- function(modules) { +extract_transforms <- function(modules) { if (inherits(modules, "teal_module")) { - modules$transformers + modules$transforms } else if (inherits(modules, "teal_modules")) { - lapply(modules$children, extract_transformers) + lapply(modules$children, extract_transforms) } } diff --git a/man/example_module.Rd b/man/example_module.Rd index 7f59bc01b6..41adb1e4d0 100644 --- a/man/example_module.Rd +++ b/man/example_module.Rd @@ -7,7 +7,7 @@ example_module( label = "example teal module", datanames = "all", - transformers = list() + transforms = list() ) } \arguments{ @@ -19,13 +19,14 @@ There are 2 reserved values that have specific behaviors: \itemize{ \item The keyword \code{"all"} includes all datasets available in the data passed to the teal application. \item \code{NULL} hides the sidebar panel completely. -\item If \code{transformers} are specified, their \code{datanames} are automatically added to this \code{datanames} +\item If \code{transforms} are specified, their \code{datanames} are automatically added to this \code{datanames} argument. }} -\item{transformers}{(\code{list} of \code{teal_data_module}) that will be applied to transform the data. -Each transform module UI will appear in the \code{teal}'s sidebar panel. -Transformers' \code{datanames} are added to the \code{datanames}. See \code{\link[=teal_transform_module]{teal_transform_module()}}.} +\item{transforms}{(\code{list} of \code{teal_transform_module}) that will be applied to transform module's data input. +Each transform module UI will appear in the \code{teal} application, unless the \code{custom_ui} attribute is set on the list. +If so, the module developer is responsible to display the UI in the module itself. \code{datanames} of the \code{transforms} +will be added to the \code{datanames}.} } \value{ A \code{teal} module which can be included in the \code{modules} argument to \code{\link[=init]{init()}}. diff --git a/man/extract_transformers.Rd b/man/extract_transforms.Rd similarity index 61% rename from man/extract_transformers.Rd rename to man/extract_transforms.Rd index 7d786e30ed..2d5d1f0a3d 100644 --- a/man/extract_transformers.Rd +++ b/man/extract_transforms.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/teal_transform_module.R -\name{extract_transformers} -\alias{extract_transformers} -\title{Extract all \code{transformers} from \code{modules}.} +\name{extract_transforms} +\alias{extract_transforms} +\title{Extract all \code{transforms} from \code{modules}.} \usage{ -extract_transformers(modules) +extract_transforms(modules) } \arguments{ \item{modules}{\code{teal_modules} or \code{teal_module}} @@ -13,6 +13,6 @@ extract_transformers(modules) A list of \code{teal_transform_module} nested in the same way as input \code{modules}. } \description{ -Extract all \code{transformers} from \code{modules}. +Extract all \code{transforms} from \code{modules}. } \keyword{internal} diff --git a/man/module_teal.Rd b/man/module_teal.Rd index 3b5461d6f2..f2bc5d95b5 100644 --- a/man/module_teal.Rd +++ b/man/module_teal.Rd @@ -66,7 +66,7 @@ performed: \itemize{ \item data loading in \code{\link{module_init_data}} \item data filtering in \code{\link{module_filter_data}} -\item data transformation in \code{\link{module_teal_transform_module}} +\item data transformation in \code{\link{module_transform_data}} } } diff --git a/man/module_teal_data.Rd b/man/module_teal_data.Rd index dee0b1087e..90fc509ad5 100644 --- a/man/module_teal_data.Rd +++ b/man/module_teal_data.Rd @@ -15,7 +15,7 @@ srv_teal_data( data_module = function(id) NULL, modules = NULL, validate_shiny_silent_error = TRUE, - is_transformer_failed = reactiveValues() + is_transform_failed = reactiveValues() ) ui_validate_reactive_teal_data(id) @@ -37,8 +37,8 @@ srv_validate_reactive_teal_data( \item{validate_shiny_silent_error}{(\code{logical}) If \code{TRUE}, then \code{shiny.silent.error} is validated and} -\item{is_transformer_failed}{(\code{reactiveValues}) contains \code{logical} flags named after each transformer. -Help to determine if any previous transformer failed, so that following transformers can be disabled +\item{is_transform_failed}{(\code{reactiveValues}) contains \code{logical} flags named after each transform. +Help to determine if any previous transform failed, so that following transforms can be disabled and display a generic failure message.} \item{data}{(\verb{reactive teal_data})} diff --git a/man/module_teal_transform_module.Rd b/man/module_teal_transform_module.Rd deleted file mode 100644 index 3f715a38f6..0000000000 --- a/man/module_teal_transform_module.Rd +++ /dev/null @@ -1,40 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/module_transform_data.R -\name{module_teal_transform_module} -\alias{module_teal_transform_module} -\alias{ui_teal_transform_module} -\alias{srv_teal_transform_module} -\title{Module to transform \code{reactive} \code{teal_data}} -\usage{ -ui_transform_data(id, transformers = list(), class = "well") - -srv_teal_transform_module( - id, - data, - transformers = list(), - modules, - is_transformer_failed = reactiveValues() -) -} -\arguments{ -\item{id}{(\code{character(1)}) Module id} - -\item{transformers}{(\code{list} of \code{teal_data_module}) that will be applied to transform the data. -Each transform module UI will appear in the \code{teal}'s sidebar panel. -Transformers' \code{datanames} are added to the \code{datanames}. See \code{\link[=teal_transform_module]{teal_transform_module()}}.} - -\item{data}{(\verb{reactive teal_data})} - -\item{modules}{(\code{teal_modules} or \code{teal_module}) For \code{datanames} validation purpose} - -\item{is_transformer_failed}{(\code{reactiveValues}) contains \code{logical} flags named after each transformer. -Help to determine if any previous transformer failed, so that following transformers can be disabled -and display a generic failure message.} -} -\value{ -\code{reactive} \code{teal_data} -} -\description{ -Module calls \code{\link[=teal_transform_module]{teal_transform_module()}} in sequence so that \verb{reactive teal_data} output -from one module is handed over to the following module's input. -} diff --git a/man/module_transform_data.Rd b/man/module_transform_data.Rd new file mode 100644 index 0000000000..84f34cd5d8 --- /dev/null +++ b/man/module_transform_data.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/module_transform_data.R +\name{module_transform_data} +\alias{module_transform_data} +\alias{ui_transform_data} +\alias{srv_transform_data} +\title{Module to transform \code{reactive} \code{teal_data}} +\usage{ +ui_transform_data(id, transforms, class = "well") + +srv_transform_data( + id, + data, + transforms, + modules = NULL, + is_transform_failed = reactiveValues() +) +} +\arguments{ +\item{id}{(\code{character(1)}) Module id} + +\item{transforms}{(\code{list} of \code{teal_transform_module}) that will be applied to transform module's data input. +Each transform module UI will appear in the \code{teal} application, unless the \code{custom_ui} attribute is set on the list. +If so, the module developer is responsible to display the UI in the module itself. \code{datanames} of the \code{transforms} +will be added to the \code{datanames}.} + +\item{data}{(\verb{reactive teal_data})} + +\item{modules}{(\code{teal_modules} or \code{teal_module}) For \code{datanames} validation purpose} + +\item{is_transform_failed}{(\code{reactiveValues}) contains \code{logical} flags named after each transform. +Help to determine if any previous transform failed, so that following transforms can be disabled +and display a generic failure message.} +} +\value{ +\code{reactive} \code{teal_data} +} +\description{ +Module calls \code{\link[=teal_transform_module]{teal_transform_module()}} in sequence so that \verb{reactive teal_data} output +from one module is handed over to the following module's input. +} diff --git a/man/teal_modules.Rd b/man/teal_modules.Rd index c7278af834..73fe9d90a5 100644 --- a/man/teal_modules.Rd +++ b/man/teal_modules.Rd @@ -21,7 +21,7 @@ module( datanames = "all", server_args = NULL, ui_args = NULL, - transformers = list() + transforms = list() ) modules(..., label = "root") @@ -72,7 +72,7 @@ There are 2 reserved values that have specific behaviors: \itemize{ \item The keyword \code{"all"} includes all datasets available in the data passed to the teal application. \item \code{NULL} hides the sidebar panel completely. -\item If \code{transformers} are specified, their \code{datanames} are automatically added to this \code{datanames} +\item If \code{transforms} are specified, their \code{datanames} are automatically added to this \code{datanames} argument. }} @@ -80,9 +80,10 @@ argument. \item{ui_args}{(named \code{list}) with additional arguments passed on to the UI function.} -\item{transformers}{(\code{list} of \code{teal_data_module}) that will be applied to transform the data. -Each transform module UI will appear in the \code{teal}'s sidebar panel. -Transformers' \code{datanames} are added to the \code{datanames}. See \code{\link[=teal_transform_module]{teal_transform_module()}}.} +\item{transforms}{(\code{list} of \code{teal_transform_module}) that will be applied to transform module's data input. +Each transform module UI will appear in the \code{teal} application, unless the \code{custom_ui} attribute is set on the list. +If so, the module developer is responsible to display the UI in the module itself. \code{datanames} of the \code{transforms} +will be added to the \code{datanames}.} \item{...}{\itemize{ \item For \code{modules()}: (\code{teal_module} or \code{teal_modules}) Objects to wrap into a tab. @@ -138,13 +139,13 @@ in a warning. Datasets with names starting with . are ignored globally unless ex in \code{datanames}. } -\section{\code{datanames} with \code{transformers}}{ -When transformers are specified, their \code{datanames} are added to the module’s \code{datanames}, which +\section{\code{datanames} with \code{transforms}}{ +When transforms are specified, their \code{datanames} are added to the module’s \code{datanames}, which changes the behavior as follows: \itemize{ -\item If \code{module(datanames)} is \code{NULL} and the \code{transformers} have defined \code{datanames}, the sidebar -will appear showing the \code{transformers}' datasets, instead of being hidden. -\item If \code{module(datanames)} is set to specific values and any \code{transformer} has \code{datanames = "all"}, +\item If \code{module(datanames)} is \code{NULL} and the \code{transforms} have defined \code{datanames}, the sidebar +will appear showing the \code{transforms}' datasets, instead of being hidden. +\item If \code{module(datanames)} is set to specific values and any \code{transform} has \code{datanames = "all"}, the module may receive extra datasets that could be unnecessary } } diff --git a/man/teal_transform_module.Rd b/man/teal_transform_module.Rd index ad17ddb897..5a1b09b228 100644 --- a/man/teal_transform_module.Rd +++ b/man/teal_transform_module.Rd @@ -2,13 +2,13 @@ % Please edit documentation in R/teal_transform_module.R \name{teal_transform_module} \alias{teal_transform_module} -\title{Data module for \code{teal} transformers.} +\title{Data module for \code{teal} transforms.} \usage{ teal_transform_module( ui = NULL, server = function(id, data) data, label = "transform module", - datanames = character(0) + datanames = "all" ) } \arguments{ @@ -19,16 +19,14 @@ teal_transform_module( \code{shiny} module server function; that takes \code{id} and \code{data} argument, where the \code{id} is the module id and \code{data} is the reactive \code{teal_data} input. The server function must return reactive expression containing \code{teal_data} object. - -The server function definition should not use \code{eventReactive} as it may lead to -unexpected behavior. -See \code{vignettes("data-transform-as-shiny-module")} for more information.} +To simplify use \code{\link[=make_teal_transform_server]{make_teal_transform_server()}}.} \item{label}{(\code{character(1)}) Label of the module.} \item{datanames}{(\code{character}) -Names of the datasets that are relevant for this module to evaluate. If set to \code{character(0)} -then module would receive \code{\link[=modules]{modules()}} \code{datanames}.} +Names of the datasets that are relevant for the module. The +filter panel will only display filters for specified \code{datanames}. The keyword \code{"all"} will show +filters of all datasets. \code{datanames} will be automatically appended to the \code{\link[=modules]{modules()}} \code{datanames}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} @@ -47,14 +45,14 @@ See vignette \code{vignette("data-transform-as-shiny-module", package = "teal")} \code{teal_transform_module}'s purpose is to modify any object created in \code{\link[teal.data:teal_data]{teal.data::teal_data}}. It means that an app-developer can use \code{teal_transform_module} to modify data but also outputted tables, listings and graphs. Some \code{\link{teal_modules}} enables app developer to inject custom shiny module to modify displayed output. -To handle these \code{decorators} inside of your module use \code{\link[=ui_teal_transform_module]{ui_teal_transform_module()}} and \link{srv_teal_transform_module}. +To handle these \code{decorators} inside of your module use \code{\link[=ui_transform_data]{ui_transform_data()}} and \link{srv_transform_data}. (todo: write more about how to handle decorators: they need to go through ui_args/srv_args and then be consumed by -ui/srv_teal_transform_module()... . Alternatively, decorators could be a \code{\link[=module]{module()}}'s argument) +ui/srv_transform_data()... . Alternatively, decorators could be a \code{\link[=module]{module()}}'s argument) } \section{\code{server} as a language}{ Server function in \code{teal_transform_module} must return \code{reactive} containing \link[teal.data:teal_data]{teal.data::teal_data} object. -Consider sinmple transformer which doesn't require any advanced reactivity, example \code{server} might have a +Consider sinmple transform which doesn't require any advanced reactivity, example \code{server} might have a following form: \if{html}{\out{
}}\preformatted{function(id, data) \{ @@ -73,12 +71,12 @@ following form: Above can be simplified to presented below, where \code{level} will be automatically substituted with respective input matched by its name. -\if{html}{\out{
}}\preformatted{make_teal_transform_module(expr = expression(x <- subset(x, col == level))) +\if{html}{\out{
}}\preformatted{make_transform_data(expr = expression(x <- subset(x, col == level))) }\if{html}{\out{
}} } \examples{ -my_transformers <- list( +my_transforms <- list( teal_transform_module( label = "Static transform for iris", datanames = "iris",