diff --git a/R/init.R b/R/init.R index a2c1fac786..a8fd46656b 100644 --- a/R/init.R +++ b/R/init.R @@ -212,7 +212,7 @@ init <- function(data, } is_modules_ok <- check_modules_datanames(modules, names(data)) - if (!isTRUE(is_modules_ok) && length(unlist(extract_transformers(modules))) == 0) { + if (!isTRUE(is_modules_ok) && length(unlist(extract_transforms(modules))) == 0) { warning(is_modules_ok, call. = FALSE) } diff --git a/R/modules.R b/R/modules.R index 181e47111e..9cfc2b1c78 100644 --- a/R/modules.R +++ b/R/modules.R @@ -329,14 +329,14 @@ modules <- function(..., label = "root") { #' @param is_root (`logical(1)`) Whether this is the root node of the tree. Only used in #' format.teal_modules(). Determines whether to show "TEAL ROOT" header #' @param what (`character`) Specifies which metadata to display. -#' Possible values: "datasets", "properties", "ui_args", "server_args", "transformers" +#' Possible values: "datasets", "properties", "ui_args", "server_args", "transforms" #' @examples #' mod <- module( #' label = "My Custom Module", #' server = function(id, data, ...) {}, #' ui = function(id, ...) {}, #' datanames = c("ADSL", "ADTTE"), -#' transformers = list(), +#' transforms = list(), #' ui_args = list(a = 1, b = "b"), #' server_args = list(x = 5, y = list(p = 1)) #' ) @@ -344,7 +344,7 @@ modules <- function(..., label = "root") { #' @export format.teal_module <- function( x, indent = 0, is_last = FALSE, parent_prefix = "", - what = c("datasets", "properties", "ui_args", "server_args", "transformers"), ...) { + what = c("datasets", "properties", "ui_args", "server_args", "transforms"), ...) { empty_text <- "" branch <- if (is_last) "L-" else "|-" current_prefix <- paste0(parent_prefix, branch, " ") @@ -381,8 +381,8 @@ format.teal_module <- function( bookmarkable <- isTRUE(attr(x, "teal_bookmarkable")) reportable <- "reporter" %in% names(formals(x$server)) - transformers <- if (length(x$transformers) > 0) { - paste(sapply(x$transformers, function(t) attr(t, "label")), collapse = ", ") + transforms <- if (length(x$transforms) > 0) { + paste(sapply(x$transforms, function(t) attr(t, "label")), collapse = ", ") } else { empty_text } @@ -417,10 +417,10 @@ format.teal_module <- function( content_prefix, "|- ", crayon::green("Server Arguments : "), server_args_formatted, "\n" ) } - if ("transformers" %in% what) { + if ("transforms" %in% what) { output <- paste0( output, - content_prefix, "L- ", crayon::magenta("Transformers : "), transformers, "\n" + content_prefix, "L- ", crayon::magenta("Transforms : "), transforms, "\n" ) } @@ -431,14 +431,14 @@ format.teal_module <- function( #' @examples #' custom_module <- function( #' label = "label", ui_args = NULL, server_args = NULL, -#' datanames = "all", transformers = list(), bk = FALSE) { +#' datanames = "all", transforms = list(), bk = FALSE) { #' ans <- module( #' label, #' server = function(id, data, ...) {}, #' ui = function(id, ...) { #' }, #' datanames = datanames, -#' transformers = transformers, +#' transforms = transforms, #' ui_args = ui_args, #' server_args = server_args #' ) @@ -475,7 +475,7 @@ format.teal_module <- function( #' cache = TRUE, #' debounce = 1000 #' ), -#' transformers = list(dummy_transformer), +#' transforms = list(dummy_transformer), #' bk = TRUE #' ), #' modules( @@ -493,7 +493,7 @@ format.teal_module <- function( #' render_type = "svg", #' cache_plots = TRUE #' ), -#' transformers = list(dummy_transformer, plot_transformer), +#' transforms = list(dummy_transformer, plot_transformer), #' bk = TRUE #' ), #' modules( @@ -525,7 +525,7 @@ format.teal_module <- function( #' ) #' #' cat(format(complete_modules)) -#' cat(format(complete_modules, what = c("ui_args", "server_args", "transformers"))) +#' cat(format(complete_modules, what = c("ui_args", "server_args", "transforms"))) #' @export format.teal_modules <- function(x, indent = 0, is_root = TRUE, is_last = FALSE, parent_prefix = "", ...) { if (is_root) { diff --git a/R/teal_transform_module.R b/R/teal_transform_module.R index 74507b6dd6..9c177bdc14 100644 --- a/R/teal_transform_module.R +++ b/R/teal_transform_module.R @@ -61,7 +61,7 @@ #' #' #' @examples -#' data_transformers <- list( +#' data_transforms <- list( #' teal_transform_module( #' label = "Static transform for iris", #' datanames = "iris", @@ -101,7 +101,7 @@ #' #' app <- init( #' data = teal_data(iris = iris), -#' modules = example_module(transforms = data_transformers) +#' modules = example_module(transforms = data_transforms) #' ) #' if (interactive()) { #' shinyApp(app$ui, app$server) diff --git a/man/teal_modules.Rd b/man/teal_modules.Rd index bfebe46704..7f379472a2 100644 --- a/man/teal_modules.Rd +++ b/man/teal_modules.Rd @@ -31,7 +31,7 @@ modules(..., label = "root") indent = 0, is_last = FALSE, parent_prefix = "", - what = c("datasets", "properties", "ui_args", "server_args", "transformers"), + what = c("datasets", "properties", "ui_args", "server_args", "transforms"), ... ) @@ -106,7 +106,7 @@ Affects the tree branch character used (L- vs |-)} used to maintain the tree structure in nested levels} \item{what}{(\code{character}) Specifies which metadata to display. -Possible values: "datasets", "properties", "ui_args", "server_args", "transformers"} +Possible values: "datasets", "properties", "ui_args", "server_args", "transforms"} \item{is_root}{(\code{logical(1)}) Whether this is the root node of the tree. Only used in format.teal_modules(). Determines whether to show "TEAL ROOT" header} @@ -228,21 +228,21 @@ mod <- module( server = function(id, data, ...) {}, ui = function(id, ...) {}, datanames = c("ADSL", "ADTTE"), - transformers = list(), + transforms = list(), ui_args = list(a = 1, b = "b"), server_args = list(x = 5, y = list(p = 1)) ) cat(format(mod)) custom_module <- function( label = "label", ui_args = NULL, server_args = NULL, - datanames = "all", transformers = list(), bk = FALSE) { + datanames = "all", transforms = list(), bk = FALSE) { ans <- module( label, server = function(id, data, ...) {}, ui = function(id, ...) { }, datanames = datanames, - transformers = transformers, + transforms = transforms, ui_args = ui_args, server_args = server_args ) @@ -279,7 +279,7 @@ complete_modules <- modules( cache = TRUE, debounce = 1000 ), - transformers = list(dummy_transformer), + transforms = list(dummy_transformer), bk = TRUE ), modules( @@ -297,7 +297,7 @@ complete_modules <- modules( render_type = "svg", cache_plots = TRUE ), - transformers = list(dummy_transformer, plot_transformer), + transforms = list(dummy_transformer, plot_transformer), bk = TRUE ), modules( @@ -329,7 +329,7 @@ complete_modules <- modules( ) cat(format(complete_modules)) -cat(format(complete_modules, what = c("ui_args", "server_args", "transformers"))) +cat(format(complete_modules, what = c("ui_args", "server_args", "transforms"))) # change the module's datanames set_datanames(module(datanames = "all"), "a") diff --git a/man/teal_transform_module.Rd b/man/teal_transform_module.Rd index c9da5a57c5..4ff69fbc9f 100644 --- a/man/teal_transform_module.Rd +++ b/man/teal_transform_module.Rd @@ -76,7 +76,7 @@ the respective input matched by its name. } \examples{ -data_transformers <- list( +data_transforms <- list( teal_transform_module( label = "Static transform for iris", datanames = "iris", @@ -116,7 +116,7 @@ data_transformers <- list( app <- init( data = teal_data(iris = iris), - modules = example_module(transforms = data_transformers) + modules = example_module(transforms = data_transforms) ) if (interactive()) { shinyApp(app$ui, app$server) diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index 1ebca65fa2..861f40b744 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -57,7 +57,7 @@ testthat::test_that("init throws when an empty `data` is used", { }) testthat::test_that( - "init throws warning when datanames in modules incompatible w/ datanames in data and there is no transformers", + "init throws warning when datanames in modules incompatible w/ datanames in data and there is no transforms", { testthat::expect_warning( init( @@ -70,7 +70,7 @@ testthat::test_that( ) testthat::test_that( - "init throws warning when datanames in modules incompatible w/ datanames in data and there is no transformers", + "init throws warning when datanames in modules incompatible w/ datanames in data and there is no transforms", { testthat::expect_warning( init( @@ -83,7 +83,7 @@ testthat::test_that( ) testthat::test_that( - "init does not throw warning when datanames in modules incompatible w/ datanames in data and there are transformers", + "init does not throw warning when datanames in modules incompatible w/ datanames in data and there are transforms", { testthat::expect_no_warning( init( @@ -91,7 +91,7 @@ testthat::test_that( modules = list( example_module( datanames = "iris", - transformers = list( + transforms = list( teal_transform_module( ui = function(id) NULL, server = function(id, data) { diff --git a/tests/testthat/test-module_teal.R b/tests/testthat/test-module_teal.R index 2e91a13f57..3a1a143329 100644 --- a/tests/testthat/test-module_teal.R +++ b/tests/testthat/test-module_teal.R @@ -65,6 +65,8 @@ transform_list <<- list( ) ) +decorators <- + testthat::describe("srv_teal lockfile", { testthat::it(paste0( "creation process is invoked for teal.lockfile.mode = \"enabled\" ", @@ -738,7 +740,7 @@ testthat::describe("srv_teal teal_modules", { module( label = "module_1", server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( label = "Dummy", server = function(id, data) { @@ -775,7 +777,7 @@ testthat::describe("srv_teal teal_modules", { module( label = "module_1", server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( label = "Dummy", server = function(id, data) { @@ -834,7 +836,7 @@ testthat::describe("srv_teal teal_modules", { module( label = "module_1", server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( label = "Dummy", ui = function(id) div("(does nothing)"), @@ -873,7 +875,7 @@ testthat::describe("srv_teal teal_modules", { module( label = "module_1", server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( label = "Dummy", server = function(id, data) { @@ -1548,7 +1550,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { module( label = "module_1", server = function(id, data) data, - transformers = transform_list[c("iris", "mtcars")] + transforms = transform_list[c("iris", "mtcars")] ) ) ), @@ -1577,7 +1579,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { module( label = "module_1", server = function(id, data) data, - transformers = transform_list[c("iris", "mtcars")] + transforms = transform_list[c("iris", "mtcars")] ) ) ), @@ -1621,7 +1623,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { module( label = "module_1", server = function(id, data) data, - transformers = transform_list[c("iris", "mtcars")] + transforms = transform_list[c("iris", "mtcars")] ) ) ), @@ -1671,7 +1673,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { label = "module_1", server = function(id, data) data, datanames = c("iris", "data_from_transform"), - transformers = list( + transforms = list( teal_transform_module( ui = function(id) NULL, server = function(id, data) { @@ -1708,7 +1710,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { modules = modules( module( server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( ui = function(id) textInput("a", "an input"), server = function(id, data) eventReactive(input$a, data()) @@ -1740,7 +1742,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { modules = modules( module( server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( ui = function(id) NULL, server = function(id, data) "whatever" @@ -1773,7 +1775,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { module( label = "module_1", server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( ui = function(id) NULL, server = function(id, data) { @@ -1801,7 +1803,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { module( label = "module_1", server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( ui = function(id) NULL, server = function(id, data) { @@ -1829,7 +1831,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { module( label = "module_1", server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( ui = function(id) NULL, server = function(id, data) { @@ -1857,7 +1859,7 @@ testthat::describe("srv_teal teal_module(s) transformer", { module( label = "module_1", server = function(id, data) data, - transformers = list( + transforms = list( teal_transform_module( ui = function(id) NULL, server = function(id, data) { @@ -2077,7 +2079,7 @@ testthat::describe("srv_teal summary table", { module( "module_1", server = function(id, data) data, - transformers = teal_transform_module( + transforms = teal_transform_module( datanames = character(0), server = function(id, data) { moduleServer(id, function(input, output, session) { @@ -2116,7 +2118,7 @@ testthat::describe("srv_teal summary table", { module( "module_1", server = function(id, data) data, - transformers = transform_list["iris"] + transforms = transform_list["iris"] ) ) ), @@ -2220,7 +2222,7 @@ testthat::describe("srv_teal summary table", { args = list( id = "test", data = data, - modules = modules(module("module_1", server = function(id, data) data, datanames = "all", transformers = list( + modules = modules(module("module_1", server = function(id, data) data, datanames = "all", transforms = list( teal_transform_module( server = function(id, data) { reactive({ diff --git a/tests/testthat/test-modules.R b/tests/testthat/test-modules.R index b1658af98c..605e0f1654 100644 --- a/tests/testthat/test-modules.R +++ b/tests/testthat/test-modules.R @@ -121,7 +121,7 @@ testthat::test_that("module() returns list of class 'teal_module' containing inp ui_args = NULL ) testthat::expect_s3_class(test_module, "teal_module") - testthat::expect_named(test_module, c("label", "server", "ui", "datanames", "server_args", "ui_args", "transformers")) + testthat::expect_named(test_module, c("label", "server", "ui", "datanames", "server_args", "ui_args", "transforms")) 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) @@ -509,12 +509,12 @@ testthat::test_that("format.teal_modules returns proper structure", { testthat::expect_equal( gsub("\033\\[[0-9;]*m", "", format(appended_mods)), - "TEAL ROOT\n |- a\n | |- Datasets : all\n | |- Properties:\n | | |- Bookmarkable : FALSE\n | | L- Reportable : FALSE\n | |- UI Arguments : \n | |- Server Arguments : \n | L- Transformers : \n |- c\n | |- Datasets : all\n | |- Properties:\n | | |- Bookmarkable : FALSE\n | | L- Reportable : FALSE\n | |- UI Arguments : \n | |- Server Arguments : \n | L- Transformers : \n L- c\n |- Datasets : all\n |- Properties:\n | |- Bookmarkable : FALSE\n | L- Reportable : FALSE\n |- UI Arguments : \n |- Server Arguments : \n L- Transformers : \n" # nolint: line_length + "TEAL ROOT\n |- a\n | |- Datasets : all\n | |- Properties:\n | | |- Bookmarkable : FALSE\n | | L- Reportable : FALSE\n | |- UI Arguments : \n | |- Server Arguments : \n | L- transforms : \n |- c\n | |- Datasets : all\n | |- Properties:\n | | |- Bookmarkable : FALSE\n | | L- Reportable : FALSE\n | |- UI Arguments : \n | |- Server Arguments : \n | L- transforms : \n L- c\n |- Datasets : all\n |- Properties:\n | |- Bookmarkable : FALSE\n | L- Reportable : FALSE\n |- UI Arguments : \n |- Server Arguments : \n L- transforms : \n" # nolint: line_length ) }) -testthat::test_that("module datanames is appended by its transformers datanames", { +testthat::test_that("module datanames is appended by its transforms datanames", { transformer_w_datanames <- teal_transform_module( ui = function(id) NULL, server = function(id, data) { @@ -530,11 +530,11 @@ testthat::test_that("module datanames is appended by its transformers datanames" datanames = c("a", "b") ) - out <- module(datanames = "c", transformers = list(transformer_w_datanames)) + out <- module(datanames = "c", transforms = list(transformer_w_datanames)) testthat::expect_identical(out$datanames, c("c", "a", "b")) }) -testthat::test_that("module datanames stays 'all' regardless of transformers", { +testthat::test_that("module datanames stays 'all' regardless of transforms", { transformer_w_datanames <- teal_transform_module( ui = function(id) NULL, server = function(id, data) { @@ -550,6 +550,6 @@ testthat::test_that("module datanames stays 'all' regardless of transformers", { datanames = c("a", "b") ) - out <- module(datanames = "all", transformers = list(transformer_w_datanames)) + out <- module(datanames = "all", transforms = list(transformer_w_datanames)) testthat::expect_identical(out$datanames, "all") }) diff --git a/vignettes/data-transform-as-shiny-module.Rmd b/vignettes/data-transform-as-shiny-module.Rmd index be8b202019..2fc687601b 100644 --- a/vignettes/data-transform-as-shiny-module.Rmd +++ b/vignettes/data-transform-as-shiny-module.Rmd @@ -12,7 +12,7 @@ vignette: > ## Introduction -`teal` version `0.16` introduced new argument in `teal::module` called `transformers`. +`teal` version `0.16` introduced new argument in `teal::module` called `transforms`. This argument allows to pass a `list` of `teal_data_module` objects that are created using `teal_transform_module()` function. The main benefit of `teal_transform_module()` is the ability to transform data before passing it @@ -59,7 +59,7 @@ data <- within(teal_data(), { mtcars <- mtcars }) -my_transformers <- list( +my_transforms <- list( teal_transform_module( label = "Custom transform for iris", ui = function(id) { @@ -85,7 +85,7 @@ my_transformers <- list( app <- init( data = data, - modules = teal::example_module(transformers = my_transformers) + modules = teal::example_module(transformers = my_transforms) ) if (interactive()) { @@ -97,9 +97,9 @@ _Note_: It is recommended to return `reactive()` with `teal_data()` in `server` If you are planning on using `eventReactive()` in the server, the event should include `data()` _(example `eventReactive(list(input$a, data()), {...})`)_. More in [this discussion](https://github.com/insightsengineering/teal/issues/1303#issuecomment-2286239832). -### Multiple Transformers +### Multiple Transforms -Note that we can add multiple `teal` transformers by including `teal_transform_module` in a list. +Note that we can add multiple `teal` transforms by including `teal_transform_module` in a list. Let's add another transformation to the `mtcars` dataset that creates a column with `rownames` of `mtcars`. Note that this module does not have interactive UI elements. @@ -110,7 +110,7 @@ data <- within(teal_data(), { mtcars <- mtcars }) -my_transformers <- list( +my_transforms <- list( teal_transform_module( label = "Custom transform for iris", ui = function(id) { @@ -155,7 +155,7 @@ my_transformers <- list( app <- init( data = data, - modules = teal::example_module(transformers = my_transformers) + modules = teal::example_module(transformers = my_transforms) ) if (interactive()) { diff --git a/vignettes/decorate-modules-output.Rmd b/vignettes/decorate-modules-output.Rmd index 475212714c..e88e8c17ee 100644 --- a/vignettes/decorate-modules-output.Rmd +++ b/vignettes/decorate-modules-output.Rmd @@ -17,7 +17,7 @@ This document outlines the customization options available for modifying the out You will learn how to use `teal_transform_module` to modify and enhance the objects created by `teal` modules, enabling you to tailor the outputs to your specific requirements without rewriting the original module code. -Adjusting input data or customizing module outputs in `teal` is accomplished using `transformers` created through +Adjusting input data or customizing module outputs in `teal` is accomplished using `transforms` created through `teal_transform_module`. This document will focus on modifying outputs, and for clarity, we will refer to these output-modifying objects as decoration objects or decorators.