diff --git a/R/tm_g_km.R b/R/tm_g_km.R index 861baab81..6c7745d6c 100644 --- a/R/tm_g_km.R +++ b/R/tm_g_km.R @@ -230,7 +230,6 @@ template_g_km <- function(dataname = "ANL", plotlist = plot_list, ncol = 1 ) - plot }, env = list( facet_var = if (length(facet_var) != 0L) as.name(facet_var), @@ -268,9 +267,19 @@ template_g_km <- function(dataname = "ANL", #' @inheritParams template_g_km #' @param facet_var ([teal.transform::choices_selected()])\cr object with #' all available choices and preselected option for names of variable that can be used for plot faceting. +#' @param decorators `r roxygen_decorators_param("tm_g_km")` #' #' @inherit module_arguments return seealso #' +#' @section Decorating `tm_g_km`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `plot` (`ggplot2`) +#' +#' 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 @@ -364,7 +373,8 @@ tm_g_km <- function(label, plot_height = c(800L, 400L, 5000L), plot_width = NULL, pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_g_km") checkmate::assert_string(label) @@ -387,6 +397,8 @@ tm_g_km <- function(label, ) checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE) checkmate::assert_class(post_output, classes = "shiny.tag", null.ok = TRUE) + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, "plot", null.ok = TRUE) args <- as.list(environment()) data_extract_list <- list( @@ -415,7 +427,8 @@ tm_g_km <- function(label, plot_width = plot_width, control_annot_surv_med = control_annot_surv_med, control_annot_coxph = control_annot_coxph, - legend_pos = legend_pos + legend_pos = legend_pos, + decorators = decorators ) ), datanames = teal.transform::get_extract_datanames(data_extract_list) @@ -512,6 +525,7 @@ ui_g_km <- function(id, ...) { ) ) ), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(a$decorators, "plot")), conditionalPanel( condition = paste0("input['", ns("compare_arms"), "']"), teal.widgets::panel_group( @@ -635,7 +649,8 @@ srv_g_km <- function(id, plot_width, control_annot_surv_med, control_annot_coxph, - legend_pos) { + legend_pos, + decorators) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") @@ -809,7 +824,13 @@ srv_g_km <- function(id, teal.code::eval_code(anl_q(), as.expression(unlist(my_calls))) }) - plot_r <- reactive(all_q()[["plot"]]) + decorated_all_q <- srv_decorate_teal_data( + id = "decorator", + data = all_q, + decorators = select_decorators(decorators, "plot"), + expr = print(plot) + ) + plot_r <- reactive(decorated_all_q()[["plot"]]) # Insert the plot into a plot with settings module from teal.widgets pws <- teal.widgets::plot_with_settings_srv( @@ -821,7 +842,7 @@ srv_g_km <- function(id, teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(all_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_all_q()))), title = label ) @@ -841,7 +862,7 @@ srv_g_km <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(all_q())) + card$append_src(teal.code::get_code(req(decorated_all_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/man/tm_g_km.Rd b/man/tm_g_km.Rd index 02308139e..67f6e17dc 100644 --- a/man/tm_g_km.Rd +++ b/man/tm_g_km.Rd @@ -31,7 +31,8 @@ tm_g_km( plot_height = c(800L, 400L, 5000L), plot_width = NULL, pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -101,6 +102,12 @@ For example a title.} \item{post_output}{(\code{shiny.tag}) optional,\cr with text placed after the output to put the output into context. For example the \code{\link[shiny:helpText]{shiny::helpText()}} elements are useful.} + +\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_g_km}" below for more details.} } \value{ a \code{teal_module} object. @@ -108,6 +115,18 @@ a \code{teal_module} object. \description{ This module produces a \code{ggplot}-style Kaplan-Meier plot for data with ADaM structure. } +\section{Decorating \code{tm_g_km}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{plot} (\code{ggplot2}) +} + +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(nestcolor)