From 25e6a1ddd6c0a6e7a345bddd66371812816dc482 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?=
<211358+averissimo@users.noreply.github.com>
Date: Wed, 4 Dec 2024 15:21:35 +0000
Subject: [PATCH] feat: decorators support for tm_t_mult_events
---
R/tm_t_mult_events.R | 37 +++++++++++++++++++++++++++++--------
man/tm_t_mult_events.Rd | 25 ++++++++++++++++++++++---
2 files changed, 51 insertions(+), 11 deletions(-)
diff --git a/R/tm_t_mult_events.R b/R/tm_t_mult_events.R
index e73306d62..4e0c8ea80 100644
--- a/R/tm_t_mult_events.R
+++ b/R/tm_t_mult_events.R
@@ -263,8 +263,7 @@ template_mult_events <- function(dataname,
# Combine tables.
y$final_table <- quote(
expr = {
- result <- sorted_result
- result
+ table <- sorted_result
}
)
@@ -280,9 +279,18 @@ template_mult_events <- function(dataname,
#' @param seq_var ([teal.transform::choices_selected()])\cr object with
#' all available choices and preselected option for variable names that can be used as analysis sequence number
#' variable. Used for counting the unique number of events.
+#' @param decorators `r roxygen_decorators_param("tm_t_mult_events")`
#'
#' @inherit module_arguments return seealso
#'
+#' #' @section Decorating `tm_t_mult_events`:
+#'
+#' This module generates the following objects, which can be modified in place using decorators:
+#' - `table` (`TableTree` - output of `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
@@ -345,7 +353,8 @@ tm_t_mult_events <- function(label,
drop_arm_levels = TRUE,
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_mult_events")
checkmate::assert_string(label)
checkmate::assert_string(dataname)
@@ -362,6 +371,8 @@ tm_t_mult_events <- 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, null.ok = TRUE, "table")
args <- as.list(environment())
@@ -386,7 +397,8 @@ tm_t_mult_events <- function(label,
label = label,
total_label = total_label,
na_level = na_level,
- basic_table_args = basic_table_args
+ basic_table_args = basic_table_args,
+ decorators = decorators
)
),
datanames = teal.transform::get_extract_datanames(data_extract_list)
@@ -438,6 +450,7 @@ ui_t_mult_events_byterm <- function(id, ...) {
)
)
),
+ ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(a$decorators, "table")),
teal.widgets::panel_group(
teal.widgets::panel_item(
"Additional Variables Info",
@@ -474,7 +487,8 @@ srv_t_mult_events_byterm <- function(id,
label,
total_label,
na_level,
- 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")
@@ -592,15 +606,22 @@ srv_t_mult_events_byterm <- function(id,
teal.code::eval_code(anl_q, as.expression(unlist(my_calls)))
})
+ decorated_table_q <- srv_decorate_teal_data(
+ id = "decorator",
+ data = all_q,
+ decorators = select_decorators(decorators, "table"),
+ expr = table
+ )
+
# Outputs to render.
- table_r <- reactive(all_q()[["result"]])
+ table_r <- reactive(decorated_table_q()[["table"]])
teal.widgets::table_with_settings_srv(id = "table", table_r = table_r)
# Render R code.
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_table_q()))),
title = label
)
@@ -619,7 +640,7 @@ srv_t_mult_events_byterm <- 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_table_q())))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
diff --git a/man/tm_t_mult_events.Rd b/man/tm_t_mult_events.Rd
index 7eb44136f..39eacbe91 100644
--- a/man/tm_t_mult_events.Rd
+++ b/man/tm_t_mult_events.Rd
@@ -20,7 +20,8 @@ tm_t_mult_events(
drop_arm_levels = TRUE,
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{
@@ -72,6 +73,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_mult_events}" below for more details.}
}
\value{
a \code{teal_module} object.
@@ -79,6 +86,18 @@ a \code{teal_module} object.
\description{
This module produces a table of multiple events by term.
}
+\details{
+\itemize{
+\item Although this function just returns \code{NULL} it has two uses, for
+the teal module users it provides a documentation of arguments that are
+commonly and consistently used in the framework. For the developer it adds a
+single reference point to import the \code{roxygen} argument description with:
+\verb{@inheritParams module_arguments}
+\item Parameters with identical descriptions & input types to those in the Standard Template Arguments section are
+excluded to reduce duplication as each module function inherits parameters from its corresponding template
+function.
+}
+}
\examples{
data <- teal_data()
data <- within(data, {
@@ -126,8 +145,8 @@ apps implementing this module can be found.
\describe{
\item{example-1}{
\href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6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