diff --git a/R/tm_t_exposure.R b/R/tm_t_exposure.R index c535217956..30c191dca0 100644 --- a/R/tm_t_exposure.R +++ b/R/tm_t_exposure.R @@ -189,8 +189,7 @@ template_exposure <- function(parentname, y$table <- substitute( expr = { - result <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent) - result + table <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent) }, env = list(parent = as.name(parentname)) ) @@ -198,8 +197,8 @@ template_exposure <- function(parentname, if (drop_levels) { y$table <- substitute( expr = { - result <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent) - rtables::prune_table(result) + table <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent) + table <- rtables::prune_table(table) }, env = list(parent = as.name(parentname)) ) @@ -224,9 +223,18 @@ template_exposure <- function(parentname, #' parameter category values. #' @param paramcd_label (`character`)\cr the column from the dataset where the value will be used to #' label the argument `paramcd`. +#' @param decorators `r roxygen_decorators_param("tm_t_exposure")` #' #' @inherit module_arguments return seealso #' +#' @section Decorating `tm_t_exposure`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `table` (`TableTree` as created from `rtables::build_table`) +#' +#' For additional details and examples of decorators, refer to the vignette +#' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation. +#' #' @examplesShinylive #' library(teal.modules.clinical) #' interactive <- function() TRUE @@ -324,7 +332,8 @@ tm_t_exposure <- function(label, na_level = default_na_str(), pre_output = NULL, post_output = NULL, - basic_table_args = teal.widgets::basic_table_args()) { + basic_table_args = teal.widgets::basic_table_args(), + decorators = NULL) { message("Initializing tm_t_exposure") checkmate::assert_string(label) checkmate::assert_string(dataname) @@ -344,6 +353,8 @@ tm_t_exposure <- function(label, checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE) checkmate::assert_class(post_output, classes = "shiny.tag", null.ok = TRUE) checkmate::assert_class(basic_table_args, "basic_table_args") + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, "table", null.ok = TRUE) data_extract_list <- list( paramcd = cs_to_des_filter(paramcd, dataname = dataname), @@ -371,7 +382,8 @@ tm_t_exposure <- function(label, total_row_label = total_row_label, na_level = na_level, basic_table_args = basic_table_args, - paramcd_label = paramcd_label + paramcd_label = paramcd_label, + decorators = decorators ) ), datanames = teal.transform::get_extract_datanames(data_extract_list) @@ -430,6 +442,7 @@ ui_t_exposure <- function(id, ...) { ), checkboxInput(ns("add_total_row"), "Add Total row", value = a$add_total_row), checkboxInput(ns("add_total"), "Add All Patients column", value = a$add_total), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(a$decorators, "table")), teal.widgets::panel_group( teal.widgets::panel_item( "Additional Variables Info", @@ -481,7 +494,8 @@ srv_t_exposure <- function(id, label, total_label, total_row_label, - basic_table_args = basic_table_args) { + basic_table_args = basic_table_args, + decorators) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") @@ -631,7 +645,14 @@ srv_t_exposure <- function(id, }) # Outputs to render. - table_r <- reactive(all_q()[["result"]]) + decorated_table_q <- srv_decorate_teal_data( + id = "decorator", + data = all_q, + decorators = select_decorators(decorators, "table"), + expr = table + ) + + table_r <- reactive(decorated_table_q()[["table"]]) teal.widgets::table_with_settings_srv( id = "table", @@ -639,9 +660,10 @@ srv_t_exposure <- function(id, ) # Render R code. + source_code_r <- reactive(teal.code::get_code(req(decorated_table_q()))) teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(all_q())), + verbatim_content = source_code_r, title = label ) @@ -660,7 +682,7 @@ srv_t_exposure <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(all_q())) + card$append_src(source_code_r()) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/man/tm_t_exposure.Rd b/man/tm_t_exposure.Rd index 7aec2d4a88..2fc9a6ec1d 100644 --- a/man/tm_t_exposure.Rd +++ b/man/tm_t_exposure.Rd @@ -28,7 +28,8 @@ tm_t_exposure( na_level = default_na_str(), pre_output = NULL, post_output = NULL, - basic_table_args = teal.widgets::basic_table_args() + basic_table_args = teal.widgets::basic_table_args(), + decorators = NULL ) } \arguments{ @@ -91,6 +92,12 @@ For example the \code{\link[shiny:helpText]{shiny::helpText()}} elements are use with settings for the module table. The argument is merged with option \code{teal.basic_table_args} and with default module arguments (hard coded in the module body). For more details, see the vignette: \code{vignette("custom-basic-table-arguments", package = "teal.widgets")}.} + +\item{decorators}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} (\code{list} of \code{teal_transform_module}, named \code{list} of \code{teal_transform_module} or \code{NULL}) optional, if not \code{NULL}, decorator for tables or plots included in the module. When a named list of \code{teal_transform_module}, the decorators are applied to the respective output objects. + +Otherwise, the decorators are applied to all objects, which is equivalent as using the name \code{default}. + +See section "Decorating \code{tm_t_exposure}" below for more details.} } \value{ a \code{teal_module} object. @@ -98,6 +105,18 @@ a \code{teal_module} object. \description{ The module produces an exposure table for risk management plan. } +\section{Decorating \code{tm_t_exposure}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{table} (\code{TableTree} as created from \code{rtables::build_table}) +} + +For additional details and examples of decorators, refer to the vignette +\code{vignette("decorate-modules-output", package = "teal")} or the \code{\link[=teal_transform_module]{teal_transform_module()}} documentation. +} + \examples{ library(dplyr)