diff --git a/DESCRIPTION b/DESCRIPTION index 3c0af05ee..e7a4d62bc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,6 +35,7 @@ Imports: DT (>= 0.13), forcats (>= 1.0.0), grid, + lifecycle (>= 0.2.0), scales, shinyjs, shinyTree (>= 0.2.8), @@ -84,7 +85,7 @@ VignetteBuilder: Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2, rstudio/shiny, insightsengineering/teal, insightsengineering/teal.transform, mllg/checkmate, tidyverse/dplyr, - rstudio/DT, tidyverse/forcats, r-lib/scales, daattali/shinyjs, + rstudio/DT, tidyverse/forcats, r-lib/lifecycle, r-lib/scales, daattali/shinyjs, shinyTree/shinyTree, rstudio/shinyvalidate, dreamRs/shinyWidgets, tidyverse/stringr, insightsengineering/teal.code, insightsengineering/teal.data, insightsengineering/teal.logger, diff --git a/R/roxygen2_templates.R b/R/roxygen2_templates.R new file mode 100644 index 000000000..d55c2aef4 --- /dev/null +++ b/R/roxygen2_templates.R @@ -0,0 +1,30 @@ +# nocov start +roxygen_decorators_param <- function(module_name) { + paste( + sep = " ", + lifecycle::badge("experimental"), + " (`list` of `teal_transform_module`, named `list` of `teal_transform_module` or", + "`NULL`) optional, if not `NULL`, decorator for tables or plots included in the module.", + "When a named list of `teal_transform_module`, the decorators are applied to the", + "respective output objects.\n\n", + "Otherwise, the decorators are applied to all objects, which is equivalent as using the name `default`.\n\n", + sprintf("See section \"Decorating `%s`\"", module_name), + "below for more details." + ) +} + +roxygen_ggplot2_args_param <- function(...) { + paste( + sep = " ", + "(`ggplot2_args`) optional, object created by [`teal.widgets::ggplot2_args()`]", + "with settings for all the plots or named list of `ggplot2_args` objects for plot-specific settings.", + "The argument is merged with options variable `teal.ggplot2_args` and default module setup.\n\n", + sprintf( + "List names should match the following: `c(\"default\", %s)`.\n\n", + paste("\"", unlist(rlang::list2(...)), "\"", collapse = ", ", sep = "") + ), + "For more details see the vignette: `vignette(\"custom-ggplot2-arguments\", package = \"teal.widgets\")`." + ) +} + +# nocov end diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index 7753c3101..c6a7fb55e 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -13,16 +13,46 @@ #' It controls the font size for plot titles, axis labels, and legends. #' - If vector of `length == 1` then the font sizes will have a fixed size. #' - while vector of `value`, `min`, and `max` allows dynamic adjustment. -#' @templateVar ggnames "Elbow plot", "Circle plot", "Biplot", "Eigenvector plot" -#' @template ggplot2_args_multi +#' @param ggplot2_args `r roxygen_ggplot2_args_param("Elbow plot", "Circle plot", "Biplot", "Eigenvector plot")` +#' @param decorators `r roxygen_decorators_param("tm_a_pca")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_a_pca`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `elbow_plot` (`ggplot2`) +#' - `circle_plot` (`ggplot2`) +#' - `biplot` (`ggplot2`) +#' - `eigenvector_plot` (`ggplot2`) +#' +#' Decorators can be applied to all outputs or only to specific objects using a +#' named list of `teal_transform_module` objects. +#' The `"default"` name is reserved for decorators that are applied to all outputs. +#' See code snippet below: +#' +#' ``` +#' tm_a_pca( +#' ..., # arguments for module +#' decorators = list( +#' default = list(teal_transform_module(...)), # applied to all outputs +#' elbow_plot = list(teal_transform_module(...)), # applied only to `elbow_plot` output +#' circle_plot = list(teal_transform_module(...)) # applied only to `circle_plot` output +#' biplot = list(teal_transform_module(...)) # applied only to `biplot` output +#' eigenvector_plot = list(teal_transform_module(...)) # applied only to `eigenvector_plot` output +#' ) +#' ) +#' ``` +#' +#' 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.general) #' interactive <- function() TRUE #' {{ next_example }} #' @examples +#' #' # general data example #' data <- teal_data() #' data <- within(data, { @@ -58,6 +88,7 @@ #' interactive <- function() TRUE #' {{ next_example }} #' @examples +#' #' # CDISC data example #' data <- teal_data() #' data <- within(data, { @@ -102,7 +133,8 @@ tm_a_pca <- function(label = "Principal Component Analysis", alpha = c(1, 0, 1), size = c(2, 1, 8), pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_a_pca") # Normalize the parameters @@ -152,6 +184,10 @@ tm_a_pca <- function(label = "Principal Component Analysis", checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + + available_decorators <- c("elbow_plot", "circle_plot", "biplot", "eigenvector_plot") + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, available_decorators) # End of assertions # Make UI args @@ -169,7 +205,8 @@ tm_a_pca <- function(label = "Principal Component Analysis", list( plot_height = plot_height, plot_width = plot_width, - ggplot2_args = ggplot2_args + ggplot2_args = ggplot2_args, + decorators = decorators ) ), datanames = teal.transform::get_extract_datanames(data_extract_list) @@ -224,6 +261,34 @@ ui_a_pca <- function(id, ...) { label = "Plot type", choices = args$plot_choices, selected = args$plot_choices[1] + ), + conditionalPanel( + condition = sprintf("input['%s'] == 'Elbow plot'", ns("plot_type")), + ui_decorate_teal_data( + ns("d_elbow_plot"), + decorators = select_decorators(args$decorators, "elbow_plot") + ) + ), + conditionalPanel( + condition = sprintf("input['%s'] == 'Circle plot'", ns("plot_type")), + ui_decorate_teal_data( + ns("d_circle_plot"), + decorators = select_decorators(args$decorators, "circle_plot") + ) + ), + conditionalPanel( + condition = sprintf("input['%s'] == 'Biplot'", ns("plot_type")), + ui_decorate_teal_data( + ns("d_biplot"), + decorators = select_decorators(args$decorators, "biplot") + ) + ), + conditionalPanel( + condition = sprintf("input['%s'] == 'Eigenvector plot'", ns("plot_type")), + ui_decorate_teal_data( + ns("d_eigenvector_plot"), + decorators = select_decorators(args$decorators, "eigenvector_plot") + ) ) ), teal.widgets::panel_item( @@ -289,7 +354,7 @@ ui_a_pca <- function(id, ...) { } # Server function for the PCA module -srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, plot_width, ggplot2_args) { +srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, plot_width, ggplot2_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") @@ -549,7 +614,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) cols <- c(getOption("ggplot2.discrete.colour"), c("lightblue", "darkred", "black"))[1:3] - g <- ggplot(mapping = aes_string(x = "component", y = "value")) + + elbow_plot <- ggplot(mapping = aes_string(x = "component", y = "value")) + geom_bar( aes(fill = "Single variance"), data = dplyr::filter(elb_dat, metric == "Proportion of Variance"), @@ -569,8 +634,6 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) + ggthemes + themes - - print(g) }, env = list( ggthemes = parsed_ggplot2_args$ggtheme, @@ -628,7 +691,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl y = sin(seq(0, 2 * pi, length.out = 100)) ) - g <- ggplot(pca_rot) + + circle_plot <- ggplot(pca_rot) + geom_point(aes_string(x = x_axis, y = y_axis)) + geom_label( aes_string(x = x_axis, y = y_axis, label = "label"), @@ -640,7 +703,6 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl labs + ggthemes + themes - print(g) }, env = list( x_axis = x_axis, @@ -861,8 +923,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl qenv, substitute( expr = { - g <- plot_call - print(g) + biplot <- plot_call }, env = list( plot_call = Reduce(function(x, y) call("+", x, y), pca_plot_biplot_expr) @@ -871,8 +932,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) } - # plot pc_var ---- - plot_pc_var <- function(base_q) { + # plot eigenvector_plot ---- + plot_eigenvector <- function(base_q) { pc <- input$pc ggtheme <- input$ggtheme @@ -938,10 +999,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl expr = { pca_rot <- pca$rotation[, pc, drop = FALSE] %>% dplyr::as_tibble(rownames = "Variable") - - g <- plot_call - - print(g) + eigenvector_plot <- plot_call }, env = list( pc = pc, @@ -951,23 +1009,54 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) } - # plot final ---- - output_q <- reactive({ - req(computation()) - teal::validate_inputs(iv_r()) - teal::validate_inputs(iv_extra, header = "Plot settings are required") + # qenvs --- + output_q <- lapply( + list( + elbow_plot = plot_elbow, + circle_plot = plot_circle, + biplot = plot_biplot, + eigenvector_plot = plot_eigenvector + ), + function(fun) { + reactive({ + req(computation()) + teal::validate_inputs(iv_r()) + teal::validate_inputs(iv_extra, header = "Plot settings are required") + fun(computation()) + }) + } + ) - switch(input$plot_type, - "Elbow plot" = plot_elbow(computation()), - "Circle plot" = plot_circle(computation()), - "Biplot" = plot_biplot(computation()), - "Eigenvector plot" = plot_pc_var(computation()), + decorated_q <- mapply( + function(obj_name, q) { + srv_decorate_teal_data( + id = sprintf("d_%s", obj_name), + data = q, + decorators = select_decorators(decorators, obj_name), + expr = reactive({ + substitute(print(.plot), env = list(.plot = as.name(obj_name))) + }), + expr_is_reactive = TRUE + ) + }, + names(output_q), + output_q + ) + + # plot final ---- + decorated_output_q <- reactive({ + switch(req(input$plot_type), + "Elbow plot" = decorated_q$elbow_plot(), + "Circle plot" = decorated_q$circle_plot(), + "Biplot" = decorated_q$biplot(), + "Eigenvector plot" = decorated_q$eigenvector_plot(), stop("Unknown plot") ) }) plot_r <- reactive({ - output_q()[["g"]] + plot_name <- gsub(" ", "_", tolower(req(input$plot_type))) + req(decorated_output_q())[[plot_name]] }) pws <- teal.widgets::plot_with_settings_srv( @@ -1034,7 +1123,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_q()))), title = "R Code for PCA" ) @@ -1057,7 +1146,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_a_regression.R b/R/tm_a_regression.R index 4e28de543..b9015c585 100644 --- a/R/tm_a_regression.R +++ b/R/tm_a_regression.R @@ -37,16 +37,27 @@ #' It takes the form of `c(value, min, max)` and it is passed to the `value_min_max` #' argument in `teal.widgets::optionalSliderInputValMinMax`. #' -#' @templateVar ggnames `r regression_names` -#' @template ggplot2_args_multi +# nolint start: line_length. +#' @param ggplot2_args `r roxygen_ggplot2_args_param("Response vs Regressor", "Residuals vs Fitted", "Scale-Location", "Cook's distance", "Residuals vs Leverage", "Cook's dist vs Leverage")` +# nolint end: line_length. +#' @param decorators `r roxygen_decorators_param("tm_a_regression")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_a_regression`: +#' +#' 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.general) #' interactive <- function() TRUE #' {{ next_example }} #' @examples +#' #' # general data example #' data <- teal_data() #' data <- within(data, { @@ -146,7 +157,8 @@ tm_a_regression <- function(label = "Regression Analysis", post_output = NULL, default_plot_type = 1, default_outlier_label = "USUBJID", - label_segment_threshold = c(0.5, 0, 10)) { + label_segment_threshold = c(0.5, 0, 10), + decorators = NULL) { message("Initializing tm_a_regression") # Normalize the parameters @@ -200,6 +212,7 @@ tm_a_regression <- function(label = "Regression Analysis", checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_choice(default_plot_type, seq.int(1L, length(plot_choices))) checkmate::assert_string(default_outlier_label) + checkmate::assert_list(decorators, "teal_transform_module", null.ok = TRUE) if (length(label_segment_threshold) == 1) { checkmate::assert_numeric(label_segment_threshold, any.missing = FALSE, finite = TRUE) @@ -212,6 +225,8 @@ tm_a_regression <- function(label = "Regression Analysis", .var.name = "label_segment_threshold" ) } + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, "plot", null.ok = TRUE) # End of assertions # Make UI args @@ -233,7 +248,8 @@ tm_a_regression <- function(label = "Regression Analysis", plot_height = plot_height, plot_width = plot_width, default_outlier_label = default_outlier_label, - ggplot2_args = ggplot2_args + ggplot2_args = ggplot2_args, + decorators = decorators ) ), datanames = teal.transform::get_extract_datanames(data_extract_list) @@ -247,7 +263,6 @@ ui_a_regression <- function(id, ...) { ns <- NS(id) args <- list(...) is_single_dataset_value <- teal.transform::is_single_dataset(args$regressor, args$response) - teal.widgets::standard_layout( output = teal.widgets::white_small_well(tags$div( teal.widgets::plot_with_settings_ui(id = ns("myplot")), @@ -306,6 +321,7 @@ ui_a_regression <- function(id, ...) { label = "Outlier label" ) ), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "plot")), teal.widgets::panel_group( teal.widgets::panel_item( title = "Plot settings", @@ -362,7 +378,8 @@ srv_a_regression <- function(id, plot_height, plot_width, ggplot2_args, - default_outlier_label) { + default_outlier_label, + decorators) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") @@ -537,450 +554,441 @@ srv_a_regression <- function(id, ) }) - output_q <- reactive({ - alpha <- input$alpha - size <- input$size - ggtheme <- input$ggtheme - input_type <- input$plot_type - show_outlier <- input$show_outlier - - teal::validate_inputs(iv_r()) - - plot_type_0 <- function() { - fit <- fit_r()[["fit"]] - ANL <- anl_merged_q()[["ANL"]] + output_plot_base <- reactive({ + base_fit <- fit_r() + teal.code::eval_code( + base_fit, + quote({ + class(fit$residuals) <- NULL - stopifnot(ncol(fit$model) == 2) + data <- ggplot2::fortify(fit) - if (!is.factor(ANL[[regression_var()$regressor]])) { - shinyjs::show("size") - shinyjs::show("alpha") - plot <- substitute( - env = list( - regressor = regression_var()$regressor, - response = regression_var()$response, - size = size, - alpha = alpha - ), - expr = ggplot( - fit$model[, 2:1], - aes_string(regressor, response) - ) + - geom_point(size = size, alpha = alpha) + - stat_smooth( - method = "lm", - formula = y ~ x, - se = FALSE - ) - ) - if (show_outlier) { - plot <- substitute( - expr = plot + outlier_label, - env = list(plot = plot, outlier_label = outlier_label()) - ) - } - } else { - shinyjs::hide("size") - shinyjs::hide("alpha") - plot <- substitute( - expr = ggplot(fit$model[, 2:1], aes_string(regressor, response)) + - geom_boxplot(), - env = list(regressor = regression_var()$regressor, response = regression_var()$response) - ) - if (show_outlier) { - plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) + smooth <- function(x, y) { + as.data.frame(stats::lowess(x, y, f = 2 / 3, iter = 3)) } - } - parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( - teal.widgets::resolve_ggplot2_args( - user_plot = ggplot2_args[["Response vs Regressor"]], - user_default = ggplot2_args$default, - module_plot = teal.widgets::ggplot2_args( - labs = list( - title = "Response vs Regressor", - x = varname_w_label(regression_var()$regressor, ANL), - y = varname_w_label(regression_var()$response, ANL) - ), - theme = list() - ) - ), - ggtheme = ggtheme - ) + smoothy_aes <- ggplot2::aes_string(x = "x", y = "y") - teal.code::eval_code( - fit_r(), - substitute( - expr = { - class(fit$residuals) <- NULL - data <- fortify(fit) - g <- plot - print(g) - }, - env = list( - plot = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) - ) - ) - ) - } - - plot_base <- function() { - base_fit <- fit_r() - teal.code::eval_code( - base_fit, - quote({ - class(fit$residuals) <- NULL - - data <- ggplot2::fortify(fit) + reg_form <- deparse(fit$call[[2]]) + }) + ) + }) - smooth <- function(x, y) { - as.data.frame(stats::lowess(x, y, f = 2 / 3, iter = 3)) - } + output_plot_0 <- reactive({ + fit <- fit_r()[["fit"]] + ANL <- anl_merged_q()[["ANL"]] - smoothy_aes <- ggplot2::aes_string(x = "x", y = "y") + stopifnot(ncol(fit$model) == 2) - reg_form <- deparse(fit$call[[2]]) - }) - ) - } - - plot_type_1 <- function(plot_base) { + if (!is.factor(ANL[[regression_var()$regressor]])) { shinyjs::show("size") shinyjs::show("alpha") plot <- substitute( - expr = ggplot(data = data, aes(.fitted, .resid)) + + expr = ggplot(fit$model[, 2:1], aes_string(regressor, response)) + geom_point(size = size, alpha = alpha) + - geom_hline(yintercept = 0, linetype = "dashed", size = 1) + - geom_line(data = smoothy, mapping = smoothy_aes), - env = list(size = size, alpha = alpha) + stat_smooth(method = "lm", formula = y ~ x, se = FALSE), + env = list( + regressor = regression_var()$regressor, + response = regression_var()$response, + size = input$size, + alpha = input$alpha + ) ) - if (show_outlier) { + if (input$show_outlier) { + plot <- substitute( + expr = plot + outlier_label, + env = list(plot = plot, outlier_label = outlier_label()) + ) + } + } else { + shinyjs::hide("size") + shinyjs::hide("alpha") + plot <- substitute( + expr = ggplot(fit$model[, 2:1], aes_string(regressor, response)) + + geom_boxplot(), + env = list(regressor = regression_var()$regressor, response = regression_var()$response) + ) + if (input$show_outlier) { plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) } + } - parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( - teal.widgets::resolve_ggplot2_args( - user_plot = ggplot2_args[["Residuals vs Fitted"]], - user_default = ggplot2_args$default, - module_plot = teal.widgets::ggplot2_args( - labs = list( - x = quote(paste0("Fitted values\nlm(", reg_form, ")")), - y = "Residuals", - title = "Residuals vs Fitted" - ) - ) - ), - ggtheme = ggtheme - ) + parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( + teal.widgets::resolve_ggplot2_args( + user_plot = ggplot2_args[["Response vs Regressor"]], + user_default = ggplot2_args$default, + module_plot = teal.widgets::ggplot2_args( + labs = list( + title = "Response vs Regressor", + x = varname_w_label(regression_var()$regressor, ANL), + y = varname_w_label(regression_var()$response, ANL) + ), + theme = list() + ) + ), + ggtheme = input$ggtheme + ) - teal.code::eval_code( - plot_base, - substitute( - expr = { - smoothy <- smooth(data$.fitted, data$.resid) - g <- plot - print(g) - }, - env = list( - plot = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) - ) + teal.code::eval_code( + fit_r(), + substitute( + expr = { + class(fit$residuals) <- NULL + data <- fortify(fit) + plot <- graph + }, + env = list( + graph = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) ) ) - } + ) + }) - plot_type_2 <- function(plot_base) { - shinyjs::show("size") - shinyjs::show("alpha") - plot <- substitute( - expr = ggplot(data = data, aes(sample = .stdresid)) + - stat_qq(size = size, alpha = alpha) + - geom_abline(linetype = "dashed"), - env = list(size = size, alpha = alpha) - ) - if (show_outlier) { - plot <- substitute( - expr = plot + - stat_qq( - geom = ggrepel::GeomTextRepel, - label = label_col %>% - data.frame(label = .) %>% - dplyr::filter(label != "cooksd == NaN") %>% - unlist(), - color = "red", - hjust = 0, - vjust = 0, - max.overlaps = Inf, - min.segment.length = label_min_segment, - segment.alpha = .5, - seed = 123 - ), - env = list(plot = plot, label_col = label_col(), label_min_segment = label_min_segment()) - ) - } + output_plot_1 <- reactive({ + plot_base <- output_plot_base() + shinyjs::show("size") + shinyjs::show("alpha") + plot <- substitute( + expr = ggplot(data = data, aes(.fitted, .resid)) + + geom_point(size = size, alpha = alpha) + + geom_hline(yintercept = 0, linetype = "dashed", size = 1) + + geom_line(data = smoothy, mapping = smoothy_aes), + env = list(size = input$size, alpha = input$alpha) + ) + if (input$show_outlier) { + plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) + } - parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( - teal.widgets::resolve_ggplot2_args( - user_plot = ggplot2_args[["Normal Q-Q"]], - user_default = ggplot2_args$default, - module_plot = teal.widgets::ggplot2_args( - labs = list( - x = quote(paste0("Theoretical Quantiles\nlm(", reg_form, ")")), - y = "Standardized residuals", - title = "Normal Q-Q" - ) + parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( + teal.widgets::resolve_ggplot2_args( + user_plot = ggplot2_args[["Residuals vs Fitted"]], + user_default = ggplot2_args$default, + module_plot = teal.widgets::ggplot2_args( + labs = list( + x = quote(paste0("Fitted values\nlm(", reg_form, ")")), + y = "Residuals", + title = "Residuals vs Fitted" ) - ), - ggtheme = ggtheme - ) + ) + ), + ggtheme = input$ggtheme + ) - teal.code::eval_code( - plot_base, - substitute( - expr = { - g <- plot - print(g) - }, - env = list( - plot = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) - ) + teal.code::eval_code( + plot_base, + substitute( + expr = { + smoothy <- smooth(data$.fitted, data$.resid) + plot <- graph + }, + env = list( + graph = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) ) ) - } + ) + }) - plot_type_3 <- function(plot_base) { - shinyjs::show("size") - shinyjs::show("alpha") + output_plot_2 <- reactive({ + shinyjs::show("size") + shinyjs::show("alpha") + plot_base <- output_plot_base() + plot <- substitute( + expr = ggplot(data = data, aes(sample = .stdresid)) + + stat_qq(size = size, alpha = alpha) + + geom_abline(linetype = "dashed"), + env = list(size = input$size, alpha = input$alpha) + ) + if (input$show_outlier) { plot <- substitute( - expr = ggplot(data = data, aes(.fitted, sqrt(abs(.stdresid)))) + - geom_point(size = size, alpha = alpha) + - geom_line(data = smoothy, mapping = smoothy_aes), - env = list(size = size, alpha = alpha) + expr = plot + + stat_qq( + geom = ggrepel::GeomTextRepel, + label = label_col %>% + data.frame(label = .) %>% + dplyr::filter(label != "cooksd == NaN") %>% + unlist(), + color = "red", + hjust = 0, + vjust = 0, + max.overlaps = Inf, + min.segment.length = label_min_segment, + segment.alpha = .5, + seed = 123 + ), + env = list(plot = plot, label_col = label_col(), label_min_segment = label_min_segment()) ) - if (show_outlier) { - plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) - } + } - parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( - teal.widgets::resolve_ggplot2_args( - user_plot = ggplot2_args[["Scale-Location"]], - user_default = ggplot2_args$default, - module_plot = teal.widgets::ggplot2_args( - labs = list( - x = quote(paste0("Fitted values\nlm(", reg_form, ")")), - y = quote(expression(sqrt(abs(`Standardized residuals`)))), - title = "Scale-Location" - ) + parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( + teal.widgets::resolve_ggplot2_args( + user_plot = ggplot2_args[["Normal Q-Q"]], + user_default = ggplot2_args$default, + module_plot = teal.widgets::ggplot2_args( + labs = list( + x = quote(paste0("Theoretical Quantiles\nlm(", reg_form, ")")), + y = "Standardized residuals", + title = "Normal Q-Q" ) - ), - ggtheme = ggtheme - ) + ) + ), + ggtheme = input$ggtheme + ) - teal.code::eval_code( - plot_base, - substitute( - expr = { - smoothy <- smooth(data$.fitted, sqrt(abs(data$.stdresid))) - g <- plot - print(g) - }, - env = list( - plot = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) - ) + teal.code::eval_code( + plot_base, + substitute( + expr = { + plot <- graph + }, + env = list( + graph = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) ) ) - } + ) + }) - plot_type_4 <- function(plot_base) { - shinyjs::hide("size") - shinyjs::show("alpha") - plot <- substitute( - expr = ggplot(data = data, aes(seq_along(.cooksd), .cooksd)) + - geom_col(alpha = alpha), - env = list(alpha = alpha) - ) - if (show_outlier) { - plot <- substitute( - expr = plot + - geom_hline( - yintercept = c( - outlier * mean(data$.cooksd, na.rm = TRUE), - mean(data$.cooksd, na.rm = TRUE) - ), - color = "red", - linetype = "dashed" - ) + - geom_text( - aes( - x = 0, - y = mean(data$.cooksd, na.rm = TRUE), - label = paste("mu", "=", round(mean(data$.cooksd, na.rm = TRUE), 4)), - vjust = -1, - hjust = 0, - color = "red", - angle = 90 - ), - parse = TRUE, - show.legend = FALSE - ) + - outlier_label, - env = list(plot = plot, outlier = input$outlier, outlier_label = outlier_label()) - ) - } + output_plot_3 <- reactive({ + shinyjs::show("size") + shinyjs::show("alpha") + plot_base <- output_plot_base() + plot <- substitute( + expr = ggplot(data = data, aes(.fitted, sqrt(abs(.stdresid)))) + + geom_point(size = size, alpha = alpha) + + geom_line(data = smoothy, mapping = smoothy_aes), + env = list(size = input$size, alpha = input$alpha) + ) + if (input$show_outlier) { + plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) + } - parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( - teal.widgets::resolve_ggplot2_args( - user_plot = ggplot2_args[["Cook's distance"]], - user_default = ggplot2_args$default, - module_plot = teal.widgets::ggplot2_args( - labs = list( - x = quote(paste0("Obs. number\nlm(", reg_form, ")")), - y = "Cook's distance", - title = "Cook's distance" - ) + parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( + teal.widgets::resolve_ggplot2_args( + user_plot = ggplot2_args[["Scale-Location"]], + user_default = ggplot2_args$default, + module_plot = teal.widgets::ggplot2_args( + labs = list( + x = quote(paste0("Fitted values\nlm(", reg_form, ")")), + y = quote(expression(sqrt(abs(`Standardized residuals`)))), + title = "Scale-Location" ) - ), - ggtheme = ggtheme - ) + ) + ), + ggtheme = input$ggtheme + ) - teal.code::eval_code( - plot_base, - substitute( - expr = { - g <- plot - print(g) - }, - env = list( - plot = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) - ) + teal.code::eval_code( + plot_base, + substitute( + expr = { + smoothy <- smooth(data$.fitted, sqrt(abs(data$.stdresid))) + plot <- graph + }, + env = list( + graph = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) ) ) - } - + ) + }) - plot_type_5 <- function(plot_base) { - shinyjs::show("size") - shinyjs::show("alpha") + output_plot_4 <- reactive({ + shinyjs::hide("size") + shinyjs::show("alpha") + plot_base <- output_plot_base() + plot <- substitute( + expr = ggplot(data = data, aes(seq_along(.cooksd), .cooksd)) + + geom_col(alpha = alpha), + env = list(alpha = input$alpha) + ) + if (input$show_outlier) { plot <- substitute( - expr = ggplot(data = data, aes(.hat, .stdresid)) + - geom_vline( - size = 1, - colour = "black", - linetype = "dashed", - xintercept = 0 - ) + + expr = plot + geom_hline( - size = 1, - colour = "black", - linetype = "dashed", - yintercept = 0 + yintercept = c( + outlier * mean(data$.cooksd, na.rm = TRUE), + mean(data$.cooksd, na.rm = TRUE) + ), + color = "red", + linetype = "dashed" ) + - geom_point(size = size, alpha = alpha) + - geom_line(data = smoothy, mapping = smoothy_aes), - env = list(size = size, alpha = alpha) + geom_text( + aes( + x = 0, + y = mean(data$.cooksd, na.rm = TRUE), + label = paste("mu", "=", round(mean(data$.cooksd, na.rm = TRUE), 4)), + vjust = -1, + hjust = 0, + color = "red", + angle = 90 + ), + parse = TRUE, + show.legend = FALSE + ) + + outlier_label, + env = list(plot = plot, outlier = input$outlier, outlier_label = outlier_label()) ) - if (show_outlier) { - plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) - } + } - parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( - teal.widgets::resolve_ggplot2_args( - user_plot = ggplot2_args[["Residuals vs Leverage"]], - user_default = ggplot2_args$default, - module_plot = teal.widgets::ggplot2_args( - labs = list( - x = quote(paste0("Standardized residuals\nlm(", reg_form, ")")), - y = "Leverage", - title = "Residuals vs Leverage" - ) + parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( + teal.widgets::resolve_ggplot2_args( + user_plot = ggplot2_args[["Cook's distance"]], + user_default = ggplot2_args$default, + module_plot = teal.widgets::ggplot2_args( + labs = list( + x = quote(paste0("Obs. number\nlm(", reg_form, ")")), + y = "Cook's distance", + title = "Cook's distance" ) - ), - ggtheme = ggtheme - ) + ) + ), + ggtheme = input$ggtheme + ) - teal.code::eval_code( - plot_base, - substitute( - expr = { - smoothy <- smooth(data$.hat, data$.stdresid) - g <- plot - print(g) - }, - env = list( - plot = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) - ) + teal.code::eval_code( + plot_base, + substitute( + expr = { + plot <- graph + }, + env = list( + graph = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) ) ) - } + ) + }) - plot_type_6 <- function(plot_base) { - shinyjs::show("size") - shinyjs::show("alpha") - plot <- substitute( - expr = ggplot(data = data, aes(.hat, .cooksd)) + - geom_vline(xintercept = 0, colour = NA) + - geom_abline( - slope = seq(0, 3, by = 0.5), - colour = "black", - linetype = "dashed", - size = 1 - ) + - geom_line(data = smoothy, mapping = smoothy_aes) + - geom_point(size = size, alpha = alpha), - env = list(size = size, alpha = alpha) - ) - if (show_outlier) { - plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) - } + output_plot_5 <- reactive({ + shinyjs::show("size") + shinyjs::show("alpha") + plot_base <- output_plot_base() + plot <- substitute( + expr = ggplot(data = data, aes(.hat, .stdresid)) + + geom_vline( + size = 1, + colour = "black", + linetype = "dashed", + xintercept = 0 + ) + + geom_hline( + size = 1, + colour = "black", + linetype = "dashed", + yintercept = 0 + ) + + geom_point(size = size, alpha = alpha) + + geom_line(data = smoothy, mapping = smoothy_aes), + env = list(size = input$size, alpha = input$alpha) + ) + if (input$show_outlier) { + plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) + } - parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( - teal.widgets::resolve_ggplot2_args( - user_plot = ggplot2_args[["Cook's dist vs Leverage"]], - user_default = ggplot2_args$default, - module_plot = teal.widgets::ggplot2_args( - labs = list( - x = quote(paste0("Leverage\nlm(", reg_form, ")")), - y = "Cooks's distance", - title = "Cook's dist vs Leverage" - ) + parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( + teal.widgets::resolve_ggplot2_args( + user_plot = ggplot2_args[["Residuals vs Leverage"]], + user_default = ggplot2_args$default, + module_plot = teal.widgets::ggplot2_args( + labs = list( + x = quote(paste0("Standardized residuals\nlm(", reg_form, ")")), + y = "Leverage", + title = "Residuals vs Leverage" ) - ), - ggtheme = ggtheme - ) + ) + ), + ggtheme = input$ggtheme + ) - teal.code::eval_code( - plot_base, - substitute( - expr = { - smoothy <- smooth(data$.hat, data$.cooksd) - g <- plot - print(g) - }, - env = list( - plot = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) - ) + teal.code::eval_code( + plot_base, + substitute( + expr = { + smoothy <- smooth(data$.hat, data$.stdresid) + plot <- graph + }, + env = list( + graph = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) ) ) + ) + }) + + output_plot_6 <- reactive({ + shinyjs::show("size") + shinyjs::show("alpha") + plot_base <- output_plot_base() + plot <- substitute( + expr = ggplot(data = data, aes(.hat, .cooksd)) + + geom_vline(xintercept = 0, colour = NA) + + geom_abline( + slope = seq(0, 3, by = 0.5), + colour = "black", + linetype = "dashed", + size = 1 + ) + + geom_line(data = smoothy, mapping = smoothy_aes) + + geom_point(size = size, alpha = alpha), + env = list(size = input$size, alpha = input$alpha) + ) + if (input$show_outlier) { + plot <- substitute(expr = plot + outlier_label, env = list(plot = plot, outlier_label = outlier_label())) } - qenv <- if (input_type == "Response vs Regressor") { - plot_type_0() - } else { - plot_base_q <- plot_base() - switch(input_type, - "Residuals vs Fitted" = plot_base_q %>% plot_type_1(), - "Normal Q-Q" = plot_base_q %>% plot_type_2(), - "Scale-Location" = plot_base_q %>% plot_type_3(), - "Cook's distance" = plot_base_q %>% plot_type_4(), - "Residuals vs Leverage" = plot_base_q %>% plot_type_5(), - "Cook's dist vs Leverage" = plot_base_q %>% plot_type_6() + parsed_ggplot2_args <- teal.widgets::parse_ggplot2_args( + teal.widgets::resolve_ggplot2_args( + user_plot = ggplot2_args[["Cook's dist vs Leverage"]], + user_default = ggplot2_args$default, + module_plot = teal.widgets::ggplot2_args( + labs = list( + x = quote(paste0("Leverage\nlm(", reg_form, ")")), + y = "Cooks's distance", + title = "Cook's dist vs Leverage" + ) + ) + ), + ggtheme = input$ggtheme + ) + + teal.code::eval_code( + plot_base, + substitute( + expr = { + smoothy <- smooth(data$.hat, data$.cooksd) + plot <- graph + }, + env = list( + graph = Reduce(function(x, y) call("+", x, y), c(plot, parsed_ggplot2_args)) + ) ) - } - qenv + ) }) + output_q <- reactive({ + teal::validate_inputs(iv_r()) + switch(input$plot_type, + "Response vs Regressor" = output_plot_0(), + "Residuals vs Fitted" = output_plot_1(), + "Normal Q-Q" = output_plot_2(), + "Scale-Location" = output_plot_3(), + "Cook's distance" = output_plot_4(), + "Residuals vs Leverage" = output_plot_5(), + "Cook's dist vs Leverage" = output_plot_6() + ) + }) - fitted <- reactive(output_q()[["fit"]]) - plot_r <- reactive(output_q()[["g"]]) + decorated_output_q <- srv_decorate_teal_data( + "decorator", + data = output_q, + decorators = select_decorators(decorators, "plot"), + expr = print(plot) + ) + + fitted <- reactive({ + req(output_q()) + decorated_output_q()[["fit"]] + }) + plot_r <- reactive({ + req(output_q()) + decorated_output_q()[["plot"]] + }) # Insert the plot into a plot_with_settings module from teal.widgets pws <- teal.widgets::plot_with_settings_srv( @@ -1000,7 +1008,7 @@ srv_a_regression <- function(id, teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_q()))), title = "R code for the regression plot", ) @@ -1019,7 +1027,7 @@ srv_a_regression <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) @@ -1027,8 +1035,3 @@ srv_a_regression <- function(id, ### }) } - -regression_names <- paste0( - '"Response vs Regressor", "Residuals vs Fitted", ', - '"Scale-Location", "Cook\'s distance", "Residuals vs Leverage"", "Cook\'s dist vs Leverage"' -) diff --git a/R/tm_data_table.R b/R/tm_data_table.R index 2a688f7d7..3cb2155a9 100644 --- a/R/tm_data_table.R +++ b/R/tm_data_table.R @@ -26,9 +26,18 @@ #' `list(searching = FALSE, pageLength = 30, lengthMenu = c(5, 15, 30, 100), scrollX = TRUE)` #' @param server_rendering (`logical`) should the data table be rendered server side #' (see `server` argument of [DT::renderDataTable()]) +#' @param decorators `r roxygen_decorators_param("tm_data_table")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_data_table`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `table` ([DT::datatable()]) +#' +#' 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.general) #' interactive <- function() TRUE @@ -96,7 +105,8 @@ tm_data_table <- function(label = "Data Table", ), server_rendering = FALSE, pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_data_table") # Start of assertions @@ -121,6 +131,9 @@ tm_data_table <- function(label = "Data Table", checkmate::assert_flag(server_rendering) checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, "table") # End of assertions ans <- module( @@ -133,7 +146,8 @@ tm_data_table <- function(label = "Data Table", datasets_selected = datasets_selected, dt_args = dt_args, dt_options = dt_options, - server_rendering = server_rendering + server_rendering = server_rendering, + decorators = decorators ), ui_args = list( pre_output = pre_output, @@ -145,9 +159,7 @@ tm_data_table <- function(label = "Data Table", } # UI page module -ui_page_data_table <- function(id, - pre_output = NULL, - post_output = NULL) { +ui_page_data_table <- function(id, pre_output = NULL, post_output = NULL) { ns <- NS(id) tagList( @@ -185,7 +197,8 @@ srv_page_data_table <- function(id, variables_selected, dt_args, dt_options, - server_rendering) { + server_rendering, + decorators) { checkmate::assert_class(data, "reactive") checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { @@ -238,7 +251,8 @@ srv_page_data_table <- function(id, ui_data_table( id = session$ns(x), choices = choices, - selected = variables_selected + selected = variables_selected, + decorators = decorators ) ) ) @@ -260,7 +274,8 @@ srv_page_data_table <- function(id, if_distinct = if_distinct, dt_args = dt_args, dt_options = dt_options, - server_rendering = server_rendering + server_rendering = server_rendering, + decorators = decorators ) } ) @@ -270,7 +285,8 @@ srv_page_data_table <- function(id, # UI function for the data_table module ui_data_table <- function(id, choices, - selected) { + selected, + decorators) { ns <- NS(id) if (!is.null(selected)) { @@ -282,6 +298,7 @@ ui_data_table <- function(id, tagList( teal.widgets::get_dt_rows(ns("data_table"), ns("dt_rows")), fluidRow( + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(decorators, "table")), teal.widgets::optionalSelectInput( ns("variables"), "Select variables:", @@ -305,7 +322,8 @@ srv_data_table <- function(id, if_distinct, dt_args, dt_options, - server_rendering) { + server_rendering, + decorators) { moduleServer(id, function(input, output, session) { iv <- shinyvalidate::InputValidator$new() iv$add_rule("variables", shinyvalidate::sv_required("Please select valid variable names")) @@ -314,27 +332,50 @@ srv_data_table <- function(id, )) iv$enable() - output$data_table <- DT::renderDataTable(server = server_rendering, { - teal::validate_inputs(iv) - + data_table_data <- reactive({ df <- data()[[dataname]] - variables <- input$variables teal::validate_has_data(df, min_nrow = 1L, msg = paste("data", dataname, "is empty")) - dataframe_selected <- if (if_distinct()) { - dplyr::count(df, dplyr::across(dplyr::all_of(variables))) - } else { - df[variables] - } + teal.code::eval_code( + data(), + substitute( + expr = { + variables <- vars + dataframe_selected <- if (if_distinct) { + dplyr::count(dataname, dplyr::across(dplyr::all_of(variables))) + } else { + dataname[variables] + } + dt_args <- args + dt_args$options <- dt_options + if (!is.null(dt_rows)) { + dt_args$options$pageLength <- dt_rows + } + dt_args$data <- dataframe_selected + table <- do.call(DT::datatable, dt_args) + }, + env = list( + dataname = as.name(dataname), + if_distinct = if_distinct(), + vars = input$variables, + args = dt_args, + dt_options = dt_options, + dt_rows = input$dt_rows + ) + ) + ) + }) - dt_args$options <- dt_options - if (!is.null(input$dt_rows)) { - dt_args$options$pageLength <- input$dt_rows - } - dt_args$data <- dataframe_selected + decorated_data_table_data <- srv_decorate_teal_data( + id = "decorator", + data = data_table_data, + decorators = select_decorators(decorators, "table") + ) - do.call(DT::datatable, dt_args) + output$data_table <- DT::renderDataTable(server = server_rendering, { + teal::validate_inputs(iv) + req(decorated_data_table_data())[["table"]] }) }) } diff --git a/R/tm_g_association.R b/R/tm_g_association.R index 3611df804..ec4a116d3 100644 --- a/R/tm_g_association.R +++ b/R/tm_g_association.R @@ -20,11 +20,19 @@ #' @param distribution_theme,association_theme (`character`) optional, `ggplot2` themes to be used by default. #' Default to `"gray"`. #' -#' @templateVar ggnames "Bivariate1", "Bivariate2" -#' @template ggplot2_args_multi +#' @param ggplot2_args `r roxygen_ggplot2_args_param("Bivariate1", "Bivariate2")` +#' @param decorators `r roxygen_decorators_param("tm_g_association")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_g_association`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `plot` (`grob` created with [ggplot2::ggplotGrob()]) +#' +#' 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.general) #' interactive <- function() TRUE @@ -130,7 +138,8 @@ tm_g_association <- function(label = "Association", association_theme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"), # nolint: line_length. pre_output = NULL, post_output = NULL, - ggplot2_args = teal.widgets::ggplot2_args()) { + ggplot2_args = teal.widgets::ggplot2_args(), + decorators = NULL) { message("Initializing tm_g_association") # Normalize the parameters @@ -166,6 +175,9 @@ tm_g_association <- function(label = "Association", plot_choices <- c("Bivariate1", "Bivariate2") checkmate::assert_list(ggplot2_args, types = "ggplot2_args") checkmate::assert_subset(names(ggplot2_args), c("default", plot_choices)) + + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, "plot") # End of assertions # Make UI args @@ -183,7 +195,7 @@ tm_g_association <- function(label = "Association", ui_args = args, server_args = c( data_extract_list, - list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args) + list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args, decorators = decorators) ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) @@ -236,6 +248,7 @@ ui_tm_g_association <- function(id, ...) { "Log transformed", value = FALSE ), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "plot")), teal.widgets::panel_group( teal.widgets::panel_item( title = "Plot settings", @@ -277,7 +290,8 @@ srv_tm_g_association <- function(id, vars, plot_height, plot_width, - ggplot2_args) { + ggplot2_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") @@ -392,8 +406,6 @@ srv_tm_g_association <- function(id, # association ref_class_cov <- ifelse(association, ref_class, "NULL") - print_call <- quote(print(p)) - var_calls <- lapply(vars_names, function(var_i) { var_class <- class(ANL[[var_i]])[1] if (is.numeric(ANL[[var_i]]) && log_transformation) { @@ -463,7 +475,6 @@ srv_tm_g_association <- function(id, ) ) } - teal.code::eval_code( merged$anl_q_r(), substitute( @@ -474,10 +485,9 @@ srv_tm_g_association <- function(id, teal.code::eval_code( substitute( expr = { - plots <- plot_calls - p <- tern::stack_grobs(grobs = lapply(plots, ggplotGrob)) - grid::grid.newpage() - grid::grid.draw(p) + plot_top <- plot_calls[[1]] + plot_bottom <- plot_calls[[1]] + plot <- tern::stack_grobs(grobs = lapply(list(plot_top, plot_bottom), ggplotGrob)) }, env = list( plot_calls = do.call( @@ -490,9 +500,19 @@ srv_tm_g_association <- function(id, ) }) + decorated_output_grob_q <- srv_decorate_teal_data( + id = "decorator", + data = output_q, + decorators = select_decorators(decorators, "plot"), + expr = { + grid::grid.newpage() + grid::grid.draw(plot) + } + ) + plot_r <- reactive({ req(iv_r()$is_valid()) - output_q()[["p"]] + req(decorated_output_grob_q())[["plot"]] }) pws <- teal.widgets::plot_with_settings_srv( @@ -508,7 +528,7 @@ srv_tm_g_association <- function(id, teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_grob_q()))), title = "Association Plot" ) @@ -527,7 +547,7 @@ srv_tm_g_association <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_grob_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_g_bivariate.R b/R/tm_g_bivariate.R index 4e93151b9..aaf9b9642 100644 --- a/R/tm_g_bivariate.R +++ b/R/tm_g_bivariate.R @@ -43,9 +43,19 @@ #' @param free_y_scales (`logical`) optional, whether Y scaling shall be changeable. #' Does not allow scaling to be changed by default (`FALSE`). #' @param swap_axes (`logical`) optional, whether to swap X and Y axes. Defaults to `FALSE`. +#' @param decorators `r roxygen_decorators_param("tm_g_bivariate")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_g_bivariate`: +#' +#' 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.general) #' interactive <- function() TRUE @@ -185,7 +195,8 @@ tm_g_bivariate <- function(label = "Bivariate Plots", ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"), ggplot2_args = teal.widgets::ggplot2_args(), pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_g_bivariate") # Normalize the parameters @@ -265,6 +276,9 @@ tm_g_bivariate <- function(label = "Bivariate Plots", checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, "plot") # End of assertions # Make UI args @@ -288,7 +302,7 @@ tm_g_bivariate <- function(label = "Bivariate Plots", ui_args = args, server_args = c( data_extract_list, - list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args) + list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args, decorators = decorators) ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) @@ -338,6 +352,7 @@ ui_g_bivariate <- function(id, ...) { justified = TRUE ) ), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "plot")), if (!is.null(args$row_facet) || !is.null(args$col_facet)) { tags$div( class = "data-extract-box", @@ -451,7 +466,8 @@ srv_g_bivariate <- function(id, size, plot_height, plot_width, - ggplot2_args) { + ggplot2_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") @@ -648,38 +664,49 @@ srv_g_bivariate <- function(id, } } - # Add labels to facets - nulled_row_facet_name <- varname_w_label(row_facet_name, ANL) - nulled_col_facet_name <- varname_w_label(col_facet_name, ANL) - without_facet <- (is.null(nulled_row_facet_name) && is.null(nulled_col_facet_name)) || !facetting - - print_call <- if (without_facet) { - quote(print(p)) - } else { - substitute( - expr = { - # Add facetting labels - # optional: grid.newpage() # nolint: commented_code. - # Prefixed with teal.modules.general as its usage will appear in "Show R code" - p <- teal.modules.general::add_facet_labels( - p, - xfacet_label = nulled_col_facet_name, - yfacet_label = nulled_row_facet_name - ) - grid::grid.newpage() - grid::grid.draw(p) - }, - env = list(nulled_col_facet_name = nulled_col_facet_name, nulled_row_facet_name = nulled_row_facet_name) - ) - } - - teal.code::eval_code(merged$anl_q_r(), substitute(expr = p <- cl, env = list(cl = cl))) %>% - teal.code::eval_code(print_call) + teal.code::eval_code(merged$anl_q_r(), substitute(expr = plot <- cl, env = list(cl = cl))) }) - plot_r <- reactive({ - output_q()[["p"]] - }) + decorated_output_q_facets <- srv_decorate_teal_data( + "decorator", + data = output_q, + decorators = select_decorators(decorators, "plot"), + expr = reactive({ + ANL <- merged$anl_q_r()[["ANL"]] + row_facet_name <- as.vector(merged$anl_input_r()$columns_source$row_facet) + col_facet_name <- as.vector(merged$anl_input_r()$columns_source$col_facet) + + # Add labels to facets + nulled_row_facet_name <- varname_w_label(row_facet_name, ANL) + nulled_col_facet_name <- varname_w_label(col_facet_name, ANL) + facetting <- (isTRUE(input$facetting) && (!is.null(row_facet_name) || !is.null(col_facet_name))) + without_facet <- (is.null(nulled_row_facet_name) && is.null(nulled_col_facet_name)) || !facetting + + print_call <- if (without_facet) { + quote(print(plot)) + } else { + substitute( + expr = { + # Add facetting labels + # optional: grid.newpage() # nolint: commented_code. + # Prefixed with teal.modules.general as its usage will appear in "Show R code" + plot <- teal.modules.general::add_facet_labels( + plot, + xfacet_label = nulled_col_facet_name, + yfacet_label = nulled_row_facet_name + ) + grid::grid.newpage() + grid::grid.draw(plot) + }, + env = list(nulled_col_facet_name = nulled_col_facet_name, nulled_row_facet_name = nulled_row_facet_name) + ) + } + print_call + }), + expr_is_reactive = TRUE + ) + + plot_r <- reactive(req(decorated_output_q_facets())[["plot"]]) pws <- teal.widgets::plot_with_settings_srv( id = "myplot", @@ -690,7 +717,7 @@ srv_g_bivariate <- function(id, teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_q_facets()))), title = "Bivariate Plot" ) @@ -709,7 +736,7 @@ srv_g_bivariate <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_q_facets))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_g_distribution.R b/R/tm_g_distribution.R index 22d5fec89..8e84ed76a 100644 --- a/R/tm_g_distribution.R +++ b/R/tm_g_distribution.R @@ -22,11 +22,40 @@ #' and `max`. #' Defaults to `c(30L, 1L, 100L)`. #' -#' @templateVar ggnames "Histogram", "QQplot" -#' @template ggplot2_args_multi +#' @param ggplot2_args `r roxygen_ggplot2_args_param("Histogram", "QQplot")` +#' @param decorators `r roxygen_decorators_param("tm_g_distribution")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_g_distribution`: +#' +#' This module generates the following objects, which can be modified in place using decorators:: +#' - `histogram_plot` (`ggplot2`) +#' - `qq_plot` (`data.frame`) +#' - `summary_table` (`data.frame`) +#' - `test_table` (`data.frame`) +#' +#' Decorators can be applied to all outputs or only to specific objects using a +#' named list of `teal_transform_module` objects. +#' The `"default"` name is reserved for decorators that are applied to all outputs. +#' See code snippet below: +#' +#' ``` +#' tm_g_distribution( +#' ..., # arguments for module +#' decorators = list( +#' default = list(teal_transform_module(...)), # applied to all outputs +#' histogram_plot = list(teal_transform_module(...)), # applied only to `histogram_plot` output +#' qq_plot = list(teal_transform_module(...)) # applied only to `qq_plot` output +#' summary_table = list(teal_transform_module(...)) # applied only to `summary_table` output +#' test_table = list(teal_transform_module(...)) # applied only to `test_table` output +#' ) +#' ) +#' ``` +#' +#' 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.general) #' interactive <- function() TRUE @@ -121,7 +150,8 @@ tm_g_distribution <- function(label = "Distribution Module", plot_height = c(600, 200, 2000), plot_width = NULL, pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_g_distribution") # Requires Suggested packages @@ -172,6 +202,11 @@ tm_g_distribution <- function(label = "Distribution Module", checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + + available_decorators <- c("histogram_plot", "qq_plot", "test_table", "summary_table") + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, names = available_decorators) + # End of assertions # Make UI args @@ -188,7 +223,12 @@ tm_g_distribution <- function(label = "Distribution Module", server = srv_distribution, server_args = c( data_extract_list, - list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args) + list( + plot_height = plot_height, + plot_width = plot_width, + ggplot2_args = ggplot2_args, + decorators = decorators + ) ), ui = ui_distribution, ui_args = args, @@ -262,6 +302,10 @@ ui_distribution <- function(id, ...) { inline = TRUE ), checkboxInput(ns("add_dens"), label = "Overlay Density", value = TRUE), + ui_decorate_teal_data( + ns("d_density"), + decorators = select_decorators(args$decorators, "histogram_plot") + ), collapsed = FALSE ) ), @@ -270,9 +314,21 @@ ui_distribution <- function(id, ...) { teal.widgets::panel_item( "QQ Plot", checkboxInput(ns("qq_line"), label = "Add diagonal line(s)", TRUE), + ui_decorate_teal_data( + ns("d_qq"), + decorators = select_decorators(args$decorators, "qq_plot") + ), collapsed = FALSE ) ), + ui_decorate_teal_data( + ns("d_summary"), + decorators = select_decorators(args$decorators, "summary_table") + ), + ui_decorate_teal_data( + ns("d_test"), + decorators = select_decorators(args$decorators, "test_table") + ), conditionalPanel( condition = paste0("input['", ns("main_type"), "'] == 'Density'"), teal.widgets::panel_item( @@ -353,7 +409,8 @@ srv_distribution <- function(id, group_var, plot_height, plot_width, - ggplot2_args) { + ggplot2_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") @@ -459,9 +516,10 @@ srv_distribution <- function(id, ) } } + rule_dist <- function(value) { - if (isTRUE(input$tabs == "QQplot" || - input$dist_tests %in% c( + if (isTRUE(input$tabs == "QQplot") || + isTRUE(input$dist_tests %in% c( "Kolmogorov-Smirnov (one-sample)", "Anderson-Darling (one-sample)", "Cramer-von Mises (one-sample)" @@ -471,6 +529,7 @@ srv_distribution <- function(id, } } } + iv_dist <- shinyvalidate::InputValidator$new() iv_dist$add_rule("t_dist", rule_dist) iv_dist$add_rule("dist_param1", rule_dist_1) @@ -654,12 +713,12 @@ srv_distribution <- function(id, ) } - if (length(s_var) == 0 && length(g_var) == 0) { - qenv <- teal.code::eval_code( + qenv <- if (length(s_var) == 0 && length(g_var) == 0) { + teal.code::eval_code( qenv, substitute( expr = { - summary_table <- ANL %>% + summary_table_data <- ANL %>% dplyr::summarise( min = round(min(dist_var_name, na.rm = TRUE), roundn), median = round(stats::median(dist_var_name, na.rm = TRUE), roundn), @@ -676,12 +735,12 @@ srv_distribution <- function(id, ) ) } else { - qenv <- teal.code::eval_code( + teal.code::eval_code( qenv, substitute( expr = { strata_vars <- strata_vars_raw - summary_table <- ANL %>% + summary_table_data <- ANL %>% dplyr::group_by_at(dplyr::vars(dplyr::any_of(strata_vars))) %>% dplyr::summarise( min = round(min(dist_var_name, na.rm = TRUE), roundn), @@ -691,7 +750,6 @@ srv_distribution <- function(id, sd = round(stats::sd(dist_var_name, na.rm = TRUE), roundn), count = dplyr::n() ) - summary_table # used to display table when running show-r-code code }, env = list( dist_var_name = dist_var_name, @@ -701,6 +759,20 @@ srv_distribution <- function(id, ) ) } + if (iv_r()$is_valid()) { + within(qenv, { + summary_table <- DT::datatable( + summary_table_data, + options = list( + autoWidth = TRUE, + columnDefs = list(list(width = "200px", targets = "_all")) + ), + rownames = FALSE + ) + }) + } else { + within(qenv, summary_table <- NULL) + } }) # distplot qenv ---- @@ -890,10 +962,7 @@ srv_distribution <- function(id, teal.code::eval_code( qenv, substitute( - expr = { - g <- plot_call - print(g) - }, + expr = histogram_plot <- plot_call, env = list(plot_call = Reduce(function(x, y) call("+", x, y), c(plot_call, parsed_ggplot2_args))) ) ) @@ -907,6 +976,7 @@ srv_distribution <- function(id, input$scales_type input$qq_line is.null(input$ggtheme) + input$tabs }, valueExpr = { dist_var <- merge_vars()$dist_var @@ -915,7 +985,6 @@ srv_distribution <- function(id, dist_var_name <- merge_vars()$dist_var_name s_var_name <- merge_vars()$s_var_name g_var_name <- merge_vars()$g_var_name - t_dist <- input$t_dist dist_param1 <- input$dist_param1 dist_param2 <- input$dist_param2 @@ -923,7 +992,7 @@ srv_distribution <- function(id, ggtheme <- input$ggtheme teal::validate_inputs(iv_r_dist(), iv_dist) - + t_dist <- req(input$t_dist) # Not validated when tab is not selected qenv <- common_q() plot_call <- if (length(s_var) == 0 && length(g_var) == 0) { @@ -1022,10 +1091,7 @@ srv_distribution <- function(id, teal.code::eval_code( qenv, substitute( - expr = { - g <- plot_call - print(g) - }, + expr = qq_plot <- plot_call, env = list(plot_call = Reduce(function(x, y) call("+", x, y), c(plot_call, parsed_ggplot2_args))) ) ) @@ -1174,7 +1240,7 @@ srv_distribution <- function(id, qenv, substitute( expr = { - test_stats <- ANL %>% + test_table_data <- ANL %>% dplyr::select(dist_var) %>% with(., broom::glance(do.call(test, args))) %>% dplyr::mutate_if(is.numeric, round, 3) @@ -1187,7 +1253,7 @@ srv_distribution <- function(id, qenv, substitute( expr = { - test_stats <- ANL %>% + test_table_data <- ANL %>% dplyr::select(dist_var, s_var, g_var) %>% dplyr::group_by_at(dplyr::vars(dplyr::any_of(groups))) %>% dplyr::do(tests = broom::glance(do.call(test, args))) %>% @@ -1198,52 +1264,88 @@ srv_distribution <- function(id, ) ) } - qenv %>% - # used to display table when running show-r-code code - teal.code::eval_code(quote(test_stats)) } ) # outputs ---- ## building main qenv - output_q <- reactive({ - tab <- input$tabs - req(tab) # tab is NULL upon app launch, hence will crash without this statement - - qenv_final <- common_q() + output_common_q <- reactive({ # wrapped in if since could lead into validate error - we do want to continue - test_r_qenv_out <- try(test_q(), silent = TRUE) - if (!inherits(test_r_qenv_out, c("try-error", "error"))) { - qenv_final <- c(qenv_final, test_q()) + test_q_out <- try(test_q(), silent = TRUE) + if (!inherits(test_q_out, c("try-error", "error"))) { + c( + common_q(), + within(test_q_out, { + test_table <- DT::datatable( + test_table_data, + options = list(scrollX = TRUE), + rownames = FALSE + ) + }) + ) + } else { + within(common_q(), test_table <- NULL) } + }) + + output_dist_q <- reactive(c(output_common_q(), req(dist_q()))) + output_qq_q <- reactive(c(output_common_q(), req(qq_q()))) + + decorated_output_dist_q <- srv_decorate_teal_data( + "d_density", + data = output_dist_q, + decorators = select_decorators(decorators, "histogram_plot"), + expr = print(histogram_plot) + ) + + decorated_output_qq_q <- srv_decorate_teal_data( + "d_qq", + data = output_qq_q, + decorators = select_decorators(decorators, "qq_plot"), + expr = print(qq_plot) + ) + + decorated_output_summary_q <- srv_decorate_teal_data( + "d_summary", + data = output_common_q, + decorators = select_decorators(decorators, "summary_table"), + expr = summary_table + ) + + decorated_output_test_q <- srv_decorate_teal_data( + "d_test", + data = output_common_q, + decorators = select_decorators(decorators, "test_table"), + expr = test_table + ) - qenv_final <- if (tab == "Histogram") { - req(dist_q()) - c(qenv_final, dist_q()) - } else if (tab == "QQplot") { - req(qq_q()) - c(qenv_final, qq_q()) + decorated_output_q <- reactive({ + tab <- req(input$tabs) # tab is NULL upon app launch, hence will crash without this statement + test_q_out <- try(test_q(), silent = TRUE) + decorated_test_q_out <- if (inherits(test_q_out, c("try-error", "error"))) { + teal.code::qenv() + } else { + decorated_output_test_q() } - qenv_final + + out_q <- switch(tab, + Histogram = decorated_output_dist_q(), + QQplot = decorated_output_qq_q() + ) + c(out_q, decorated_output_summary_q(), decorated_test_q_out) }) - dist_r <- reactive(dist_q()[["g"]]) + dist_r <- reactive(req(decorated_output_dist_q())[["histogram_plot"]]) - qq_r <- reactive(qq_q()[["g"]]) + qq_r <- reactive(req(decorated_output_qq_q())[["qq_plot"]]) - output$summary_table <- DT::renderDataTable( - expr = if (iv_r()$is_valid()) common_q()[["summary_table"]] else NULL, - options = list( - autoWidth = TRUE, - columnDefs = list(list(width = "200px", targets = "_all")) - ), - rownames = FALSE - ) + output$summary_table <- DT::renderDataTable(expr = decorated_output_summary_q()[["summary_table"]]) tests_r <- reactive({ req(iv_r()$is_valid()) teal::validate_inputs(iv_r_dist()) - test_q()[["test_stats"]] + req(test_q()) # Ensure original errors are displayed + decorated_output_test_q()[["test_table"]] }) pws1 <- teal.widgets::plot_with_settings_srv( @@ -1263,14 +1365,12 @@ srv_distribution <- function(id, ) output$t_stats <- DT::renderDataTable( - expr = tests_r(), - options = list(scrollX = TRUE), - rownames = FALSE + expr = tests_r() ) teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_q()))), title = "R Code for distribution" ) @@ -1302,7 +1402,7 @@ srv_distribution <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_g_response.R b/R/tm_g_response.R index a593c46a4..85590ed9f 100644 --- a/R/tm_g_response.R +++ b/R/tm_g_response.R @@ -33,12 +33,21 @@ #' @param freq (`logical(1)`) #' Indicates whether to display frequency (`TRUE`) or density (`FALSE`). #' Defaults to density (`FALSE`). +#' @param decorators `r roxygen_decorators_param("tm_g_response")` #' #' @inherit shared_params return #' #' @note For more examples, please see the vignette "Using response plot" via #' `vignette("using-response-plot", package = "teal.modules.general")`. #' +#' @section Decorating `tm_g_response`: +#' +#' 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.general) #' interactive <- function() TRUE @@ -147,7 +156,8 @@ tm_g_response <- function(label = "Response Plot", ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"), ggplot2_args = teal.widgets::ggplot2_args(), pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_g_response") # Normalize the parameters @@ -191,6 +201,9 @@ tm_g_response <- function(label = "Response Plot", checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, "plot") # End of assertions # Make UI args @@ -210,7 +223,12 @@ tm_g_response <- function(label = "Response Plot", ui_args = args, server_args = c( data_extract_list, - list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args) + list( + plot_height = plot_height, + plot_width = plot_width, + ggplot2_args = ggplot2_args, + decorators = decorators + ) ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) @@ -269,6 +287,7 @@ ui_g_response <- function(id, ...) { selected = ifelse(args$freq, "frequency", "density"), justified = TRUE ), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "plot")), teal.widgets::panel_group( teal.widgets::panel_item( title = "Plot settings", @@ -304,7 +323,8 @@ srv_g_response <- function(id, col_facet, plot_height, plot_width, - ggplot2_args) { + ggplot2_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") @@ -523,8 +543,7 @@ srv_g_response <- function(id, ) plot_call <- substitute(expr = { - p <- plot_call + labs + ggthemes + themes - print(p) + plot <- plot_call + labs + ggthemes + themes }, env = list( plot_call = plot_call, labs = parsed_ggplot2_args$labs, @@ -535,7 +554,14 @@ srv_g_response <- function(id, teal.code::eval_code(qenv, plot_call) }) - plot_r <- reactive(output_q()[["p"]]) + decorated_output_plot_q <- srv_decorate_teal_data( + id = "decorator", + data = output_q, + decorators = select_decorators(decorators, "plot"), + expr = print(plot) + ) + + plot_r <- reactive(req(decorated_output_plot_q())[["plot"]]) # Insert the plot into a plot_with_settings module from teal.widgets pws <- teal.widgets::plot_with_settings_srv( @@ -547,7 +573,7 @@ srv_g_response <- function(id, teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_plot_q()))), title = "Show R Code for Response" ) @@ -566,7 +592,7 @@ srv_g_response <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_plot_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_g_scatterplot.R b/R/tm_g_scatterplot.R index 1f2d9d58a..28d9b0bda 100644 --- a/R/tm_g_scatterplot.R +++ b/R/tm_g_scatterplot.R @@ -27,9 +27,19 @@ #' `vignette("ggplot2-specs", package="ggplot2")`. #' @param max_deg (`integer`) optional, maximum degree for the polynomial trend line. Must not be less than 1. #' @param table_dec (`integer`) optional, number of decimal places used to round numeric values in the table. +#' @param decorators `r roxygen_decorators_param("tm_g_scatterplot")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_g_scatterplot`: +#' +#' 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.general) #' interactive <- function() TRUE @@ -229,7 +239,8 @@ tm_g_scatterplot <- function(label = "Scatterplot", pre_output = NULL, post_output = NULL, table_dec = 4, - ggplot2_args = teal.widgets::ggplot2_args()) { + ggplot2_args = teal.widgets::ggplot2_args(), + decorators = NULL) { message("Initializing tm_g_scatterplot") # Requires Suggested packages @@ -297,6 +308,10 @@ tm_g_scatterplot <- function(label = "Scatterplot", checkmate::assert_scalar(table_dec) checkmate::assert_class(ggplot2_args, "ggplot2_args") + + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, "plot") + # End of assertions # Make UI args @@ -318,7 +333,13 @@ tm_g_scatterplot <- function(label = "Scatterplot", ui_args = args, server_args = c( data_extract_list, - list(plot_height = plot_height, plot_width = plot_width, table_dec = table_dec, ggplot2_args = ggplot2_args) + list( + plot_height = plot_height, + plot_width = plot_width, + table_dec = table_dec, + ggplot2_args = ggplot2_args, + decorators = decorators + ) ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) @@ -413,6 +434,7 @@ ui_g_scatterplot <- function(id, ...) { is_single_dataset = is_single_dataset_value ) }, + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "plot")), teal.widgets::panel_group( teal.widgets::panel_item( title = "Plot settings", @@ -491,7 +513,8 @@ srv_g_scatterplot <- function(id, plot_height, plot_width, table_dec, - ggplot2_args) { + ggplot2_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") @@ -981,13 +1004,19 @@ srv_g_scatterplot <- function(id, ) } - plot_call <- substitute(expr = p <- plot_call, env = list(plot_call = plot_call)) + plot_call <- substitute(expr = plot <- plot_call, env = list(plot_call = plot_call)) - teal.code::eval_code(plot_q, plot_call) %>% - teal.code::eval_code(quote(print(p))) + teal.code::eval_code(plot_q, plot_call) }) - plot_r <- reactive(output_q()[["p"]]) + decorated_output_plot_q <- srv_decorate_teal_data( + id = "decorator", + data = output_q, + decorators = select_decorators(decorators, "plot"), + expr = print(plot) + ) + + plot_r <- reactive(req(decorated_output_plot_q())[["plot"]]) # Insert the plot into a plot_with_settings module from teal.widgets pws <- teal.widgets::plot_with_settings_srv( @@ -1028,7 +1057,7 @@ srv_g_scatterplot <- function(id, teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_plot_q()))), title = "R Code for scatterplot" ) @@ -1047,7 +1076,7 @@ srv_g_scatterplot <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_plot_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_g_scatterplotmatrix.R b/R/tm_g_scatterplotmatrix.R index 70f5d4b7e..ae1be8198 100644 --- a/R/tm_g_scatterplotmatrix.R +++ b/R/tm_g_scatterplotmatrix.R @@ -15,9 +15,18 @@ #' Specifies plotting variables from an incoming dataset with filtering and selecting. In case of #' `data_extract_spec` use `select_spec(..., ordered = TRUE)` if plot elements should be #' rendered according to selection order. +#' @param decorators `r roxygen_decorators_param("tm_g_scatterplotmatrix")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_g_scatterplotmatrix`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `plot` (`trellis` - output of `lattice::splom`) +#' +#' 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.general) #' interactive <- function() TRUE @@ -168,7 +177,8 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix", plot_height = c(600, 200, 2000), plot_width = NULL, pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_g_scatterplotmatrix") # Requires Suggested packages @@ -193,6 +203,9 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix", checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, "plot") # End of assertions # Make UI args @@ -203,7 +216,12 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix", server = srv_g_scatterplotmatrix, ui = ui_g_scatterplotmatrix, ui_args = args, - server_args = list(variables = variables, plot_height = plot_height, plot_width = plot_width), + server_args = list( + variables = variables, + plot_height = plot_height, + plot_width = plot_width, + decorators = decorators + ), datanames = teal.transform::get_extract_datanames(variables) ) attr(ans, "teal_bookmarkable") <- TRUE @@ -234,6 +252,7 @@ ui_g_scatterplotmatrix <- function(id, ...) { is_single_dataset = is_single_dataset_value ), tags$hr(), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "plot")), teal.widgets::panel_group( teal.widgets::panel_item( title = "Plot settings", @@ -267,7 +286,14 @@ ui_g_scatterplotmatrix <- function(id, ...) { } # Server function for the scatterplot matrix module -srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variables, plot_height, plot_width) { +srv_g_scatterplotmatrix <- function(id, + data, + reporter, + filter_panel_api, + variables, + plot_height, + plot_width, + decorators) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") @@ -364,7 +390,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab qenv, substitute( expr = { - g <- lattice::splom( + plot <- lattice::splom( ANL, varnames = varnames_value, panel = function(x, y, ...) { @@ -388,7 +414,6 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab alpha = alpha_value, cex = cex_value ) - print(g) }, env = list( varnames_value = varnames, @@ -407,8 +432,13 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab qenv, substitute( expr = { - g <- lattice::splom(ANL, varnames = varnames_value, pch = 16, alpha = alpha_value, cex = cex_value) - g + plot <- lattice::splom( + ANL, + varnames = varnames_value, + pch = 16, + alpha = alpha_value, + cex = cex_value + ) }, env = list(varnames_value = varnames, alpha_value = alpha, cex_value = cex) ) @@ -417,7 +447,14 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab qenv }) - plot_r <- reactive(output_q()[["g"]]) + decorated_output_q <- srv_decorate_teal_data( + id = "decorator", + data = output_q, + decorators = select_decorators(decorators, "plot"), + expr = print(plot) + ) + + plot_r <- reactive(req(decorated_output_q())[["plot"]]) # Insert the plot into a plot_with_settings module pws <- teal.widgets::plot_with_settings_srv( @@ -451,7 +488,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_q()))), title = "Show R Code for Scatterplotmatrix" ) @@ -470,7 +507,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_missing_data.R b/R/tm_missing_data.R index d57c616bd..f3309c802 100644 --- a/R/tm_missing_data.R +++ b/R/tm_missing_data.R @@ -10,13 +10,43 @@ #' @param parent_dataname (`character(1)`) Specifies the parent dataset name. Default is `ADSL` for `CDISC` data. #' If provided and exists, enables additional analysis "by subject". For non-`CDISC` data, this parameter can be #' ignored. +# nolint start: line_length. #' @param ggtheme (`character`) optional, specifies the default `ggplot2` theme for plots. Defaults to `classic`. -#' -#' @templateVar ggnames "Summary Obs", "Summary Patients", "Combinations Main", "Combinations Hist", "By Subject" -#' @template ggplot2_args_multi +#' @param ggplot2_args `r roxygen_ggplot2_args_param("Summary Obs", "Summary Patients", "Combinations Main", "Combinations Hist", "By Subject")` +# nolint end: line_length. +#' @param decorators `r roxygen_decorators_param("tm_missing_data")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_missing_data`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `summary_plot` (`grob` created with [ggplot2::ggplotGrob()]) +#' - `combination_plot` (`grob` created with [ggplot2::ggplotGrob()]) +#' - `by_subject_plot` (`ggplot2`) +#' - `table` ([DT::datatable()]) +#' +#' Decorators can be applied to all outputs or only to specific objects using a +#' named list of `teal_transform_module` objects. +#' The `"default"` name is reserved for decorators that are applied to all outputs. +#' See code snippet below: +#' +#' ``` +#' tm_missing_data( +#' ..., # arguments for module +#' decorators = list( +#' default = list(teal_transform_module(...)), # applied to all outputs +#' summary_plot = list(teal_transform_module(...)), # applied only to `summary_plot` output +#' combination_plot = list(teal_transform_module(...)) # applied only to `combination_plot` output +#' by_subject_plot = list(teal_transform_module(...)) # applied only to `by_subject_plot` output +#' table = list(teal_transform_module(...)) # applied only to `table` output +#' ) +#' ) +#' ``` +#' +#' 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.general) #' interactive <- function() TRUE @@ -87,7 +117,8 @@ tm_missing_data <- function(label = "Missing data", "Combinations Main" = teal.widgets::ggplot2_args(labs = list(title = NULL)) ), pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_missing_data") # Requires Suggested packages @@ -121,14 +152,22 @@ tm_missing_data <- function(label = "Missing data", checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + + available_decorators <- c("summary_plot", "combination_plot", "by_subject_plot", "summary_table") + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, names = available_decorators) # End of assertions ans <- module( label, server = srv_page_missing_data, server_args = list( - parent_dataname = parent_dataname, plot_height = plot_height, - plot_width = plot_width, ggplot2_args = ggplot2_args, ggtheme = ggtheme + parent_dataname = parent_dataname, + plot_height = plot_height, + plot_width = plot_width, + ggplot2_args = ggplot2_args, + ggtheme = ggtheme, + decorators = decorators ), ui = ui_page_missing_data, datanames = "all", @@ -165,7 +204,7 @@ ui_page_missing_data <- function(id, pre_output = NULL, post_output = NULL) { # Server function for the missing data module (all datasets) srv_page_missing_data <- function(id, data, reporter, filter_panel_api, parent_dataname, - plot_height, plot_width, ggplot2_args, ggtheme) { + plot_height, plot_width, ggplot2_args, ggtheme, decorators) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") moduleServer(id, function(input, output, session) { @@ -215,7 +254,8 @@ srv_page_missing_data <- function(id, data, reporter, filter_panel_api, parent_d id = ns(x), summary_per_patient = if_subject_plot, ggtheme = ggtheme, - datanames = datanames + datanames = datanames, + decorators = decorators ) ) } @@ -248,7 +288,8 @@ srv_page_missing_data <- function(id, data, reporter, filter_panel_api, parent_d parent_dataname = parent_dataname, plot_height = plot_height, plot_width = plot_width, - ggplot2_args = ggplot2_args + ggplot2_args = ggplot2_args, + decorators = decorators ) } ) @@ -326,7 +367,7 @@ ui_missing_data <- function(id, by_subject_plot = FALSE) { } # UI encoding for the missing data module (all datasets) -encoding_missing_data <- function(id, summary_per_patient = FALSE, ggtheme, datanames) { +encoding_missing_data <- function(id, summary_per_patient = FALSE, ggtheme, datanames, decorators) { ns <- NS(id) tagList( @@ -381,25 +422,30 @@ encoding_missing_data <- function(id, summary_per_patient = FALSE, ggtheme, data ), value = FALSE ) - } + }, + ui_decorate_teal_data(ns("dec_summary_plot"), decorators = select_decorators(decorators, "summary_plot")) ), conditionalPanel( is_tab_active_js(ns("summary_type"), "Combinations"), - uiOutput(ns("cutoff")) + uiOutput(ns("cutoff")), + ui_decorate_teal_data(ns("dec_combination_plot"), decorators = select_decorators(decorators, "combination_plot")) + ), + conditionalPanel( + is_tab_active_js(ns("summary_type"), "Grouped by Subject"), + ui_decorate_teal_data(ns("dec_by_subject_plot"), decorators = select_decorators(decorators, "by_subject_plot")) ), conditionalPanel( is_tab_active_js(ns("summary_type"), "By Variable Levels"), - tagList( - uiOutput(ns("group_by_var_ui")), - uiOutput(ns("group_by_vals_ui")), - radioButtons( - ns("count_type"), - label = "Display missing as", - choices = c("counts", "proportions"), - selected = "counts", - inline = TRUE - ) - ) + uiOutput(ns("group_by_var_ui")), + uiOutput(ns("group_by_vals_ui")), + radioButtons( + ns("count_type"), + label = "Display missing as", + choices = c("counts", "proportions"), + selected = "counts", + inline = TRUE + ), + ui_decorate_teal_data(ns("dec_summary_table"), decorators = select_decorators(decorators, "summary_table")) ), teal.widgets::panel_item( title = "Plot settings", @@ -415,8 +461,16 @@ encoding_missing_data <- function(id, summary_per_patient = FALSE, ggtheme, data } # Server function for the missing data (single dataset) -srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, parent_dataname, - plot_height, plot_width, ggplot2_args) { +srv_missing_data <- function(id, + data, + reporter, + filter_panel_api, + dataname, + parent_dataname, + plot_height, + plot_width, + ggplot2_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") @@ -462,7 +516,6 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par iv }) - data_parent_keys <- reactive({ if (length(parent_dataname) > 0 && parent_dataname %in% names(data())) { keys <- teal.data::join_keys(data())[[dataname]] @@ -553,6 +606,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ) }) + # Keep encoding panel up-to-date output$variables <- renderUI({ choices <- split(x = vars_summary()$key, f = vars_summary()$label, drop = TRUE) %>% rev() selected <- choices <- unname(unlist(choices)) @@ -631,7 +685,6 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par prev_group_by_var(input$group_by_var) # set current group_by_var validate(need(length(choices) < 100, "Please select group-by variable with fewer than 100 unique values")) - teal.widgets::optionalSelectInput( ns("group_by_vals"), label = "Filter levels", @@ -642,12 +695,47 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ) }) + combination_cutoff_q <- reactive({ + req(common_code_q()) + teal.code::eval_code( + common_code_q(), + quote( + combination_cutoff <- ANL %>% + dplyr::mutate_all(is.na) %>% + dplyr::group_by_all() %>% + dplyr::tally() %>% + dplyr::ungroup() + ) + ) + }) + + output$cutoff <- renderUI({ + x <- combination_cutoff_q()[["combination_cutoff"]]$n + + # select 10-th from the top + n <- length(x) + idx <- max(1, n - 10) + prev_value <- isolate(input$combination_cutoff) + value <- if (is.null(prev_value) || prev_value > max(x) || prev_value < min(x)) { + sort(x, partial = idx)[idx] + } else { + prev_value + } + + teal.widgets::optionalSliderInputValMinMax( + ns("combination_cutoff"), + "Combination cut-off", + c(value, range(x)) + ) + }) + + # Prepare qenvs for output objects + summary_plot_q <- reactive({ req(input$summary_type == "Summary") # needed to trigger show r code update on tab change teal::validate_has_data(data_r(), 1) qenv <- common_code_q() - if (input$any_na) { new_col_name <- "**anyna**" qenv <- teal.code::eval_code( @@ -718,7 +806,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par qenv <- teal.code::eval_code( qenv, substitute( - p1 <- summary_plot_obs %>% + summary_plot_top <- summary_plot_obs %>% ggplot() + aes( x = factor(create_cols_labels(col), levels = x_levels), @@ -800,7 +888,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par qenv <- teal.code::eval_code( qenv, substitute( - p2 <- summary_plot_patients %>% + summary_plot_bottom <- summary_plot_patients %>% ggplot() + aes_( x = ~ factor(create_cols_labels(col), levels = x_levels), @@ -833,65 +921,22 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ggthemes = parsed_ggplot2_args$ggtheme ) ) - ) %>% - teal.code::eval_code( - quote({ - g1 <- ggplotGrob(p1) - g2 <- ggplotGrob(p2) - g <- gridExtra::gtable_cbind(g1, g2, size = "first") - g$heights <- grid::unit.pmax(g1$heights, g2$heights) - grid::grid.newpage() - }) - ) - } else { - qenv <- teal.code::eval_code( - qenv, - quote({ - g <- ggplotGrob(p1) - grid::grid.newpage() - }) ) } - teal.code::eval_code( - qenv, - quote(grid::grid.draw(g)) - ) - }) - - summary_plot_r <- reactive(summary_plot_q()[["g"]]) - - combination_cutoff_q <- reactive({ - req(common_code_q()) - teal.code::eval_code( - common_code_q(), - quote( - combination_cutoff <- ANL %>% - dplyr::mutate_all(is.na) %>% - dplyr::group_by_all() %>% - dplyr::tally() %>% - dplyr::ungroup() - ) - ) - }) - - output$cutoff <- renderUI({ - x <- combination_cutoff_q()[["combination_cutoff"]]$n - - # select 10-th from the top - n <- length(x) - idx <- max(1, n - 10) - prev_value <- isolate(input$combination_cutoff) - value <- `if`( - is.null(prev_value) || prev_value > max(x) || prev_value < min(x), - sort(x, partial = idx)[idx], prev_value - ) - - teal.widgets::optionalSliderInputValMinMax( - ns("combination_cutoff"), - "Combination cut-off", - c(value, range(x)) - ) + if (isTRUE(input$if_patients_plot)) { + within(qenv, { + g1 <- ggplotGrob(summary_plot_top) + g2 <- ggplotGrob(summary_plot_bottom) + summary_plot <- gridExtra::gtable_cbind(g1, g2, size = "first") + summary_plot$heights <- grid::unit.pmax(g1$heights, g2$heights) + }) + } else { + within(qenv, { + g1 <- ggplotGrob(summary_plot_top) + summary_plot <- g1 + }) + } }) combination_plot_q <- reactive({ @@ -972,11 +1017,11 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ggtheme = input$ggtheme ) - teal.code::eval_code( + qenv <- teal.code::eval_code( qenv, substitute( expr = { - p1 <- data_combination_plot_cutoff %>% + combination_plot_top <- data_combination_plot_cutoff %>% dplyr::select(id, n) %>% dplyr::distinct() %>% ggplot(aes(x = id, y = n)) + @@ -994,7 +1039,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par graph_number_rows <- length(unique(data_combination_plot_cutoff$id)) graph_number_cols <- nrow(data_combination_plot_cutoff) / graph_number_rows - p2 <- data_combination_plot_cutoff %>% ggplot() + + combination_plot_bottom <- data_combination_plot_cutoff %>% ggplot() + aes(x = create_cols_labels(key), y = id - 0.5, fill = value) + geom_tile(alpha = 0.85, height = 0.95) + scale_fill_manual( @@ -1008,14 +1053,6 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par labs2 + ggthemes2 + themes2 - - g1 <- ggplotGrob(p1) - g2 <- ggplotGrob(p2) - - g <- gridExtra::gtable_rbind(g1, g2, size = "last") - g$heights[7] <- grid::unit(0.2, "null") # rescale to get the bar chart smaller - grid::grid.newpage() - grid::grid.draw(g) }, env = list( labs1 = parsed_ggplot2_args1$labs, @@ -1027,9 +1064,15 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ) ) ) - }) - combination_plot_r <- reactive(combination_plot_q()[["g"]]) + within(qenv, { + g1 <- ggplotGrob(combination_plot_top) + g2 <- ggplotGrob(combination_plot_bottom) + + combination_plot <- gridExtra::gtable_rbind(g1, g2, size = "last") + combination_plot$heights[7] <- grid::unit(0.2, "null") # rescale to get the bar chart smaller + }) + }) summary_table_q <- reactive({ req( @@ -1067,11 +1110,9 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par function(x) round(sum(is.na(x)) / length(x), 4) } - qenv <- common_code_q() - - if (!is.null(group_var)) { - qenv <- teal.code::eval_code( - qenv, + qenv <- if (!is.null(group_var)) { + teal.code::eval_code( + common_code_q(), substitute( expr = { summary_data <- ANL %>% @@ -1093,8 +1134,8 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ) ) } else { - qenv <- teal.code::eval_code( - qenv, + teal.code::eval_code( + common_code_q(), substitute( expr = summary_data <- ANL %>% dplyr::summarise_all(summ_fn) %>% @@ -1108,11 +1149,9 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ) } - teal.code::eval_code(qenv, quote(summary_data)) + within(qenv, table <- DT::datatable(summary_data)) }) - summary_table_r <- reactive(summary_table_q()[["summary_data"]]) - by_subject_plot_q <- reactive({ # needed to trigger show r code update on tab change req(input$summary_type == "Grouped by Subject", common_code_q()) @@ -1188,7 +1227,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par teal.code::eval_code( substitute( expr = { - g <- ggplot(summary_plot_patients, aes( + by_subject_plot <- ggplot(summary_plot_patients, aes( x = factor(id, levels = order_subjects), y = factor(col, levels = ordered_columns[["column"]]), fill = isna @@ -1209,7 +1248,6 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par labs + ggthemes + themes - print(g) }, env = list( labs = parsed_ggplot2_args$labs, @@ -1220,21 +1258,73 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ) }) - by_subject_plot_r <- reactive(by_subject_plot_q()[["g"]]) + # Decorated outputs - output$levels_table <- DT::renderDataTable( + # Summary_plot_q + decorated_summary_plot_q <- srv_decorate_teal_data( + id = "dec_summary_plot", + data = summary_plot_q, + decorators = select_decorators(decorators, "summary_plot"), expr = { - if (length(input$variables_select) == 0) { - # so that zeroRecords message gets printed - # using tibble as it supports weird column names, such as " " - tibble::tibble(` ` = logical(0)) - } else { - summary_table_r() - } - }, - options = list(language = list(zeroRecords = "No variable selected"), pageLength = input$levels_table_rows) + grid::grid.newpage() + grid::grid.draw(summary_plot) + } ) + decorated_combination_plot_q <- srv_decorate_teal_data( + id = "dec_combination_plot", + data = combination_plot_q, + decorators = select_decorators(decorators, "combination_plot"), + expr = { + grid::grid.newpage() + grid::grid.draw(combination_plot) + } + ) + + decorated_summary_table_q <- srv_decorate_teal_data( + id = "dec_summary_table", + data = summary_table_q, + decorators = select_decorators(decorators, "summary_table"), + expr = table + ) + + decorated_by_subject_plot_q <- srv_decorate_teal_data( + id = "dec_by_subject_plot", + data = by_subject_plot_q, + decorators = select_decorators(decorators, "by_subject_plot"), + expr = print(by_subject_plot) + ) + + # Plots & tables reactives + + summary_plot_r <- reactive({ + req(decorated_summary_plot_q())[["summary_plot"]] + }) + + combination_plot_r <- reactive({ + req(decorated_combination_plot_q())[["combination_plot"]] + }) + + summary_table_r <- reactive({ + req(decorated_summary_table_q()) + + if (length(input$variables_select) == 0) { + # so that zeroRecords message gets printed + # using tibble as it supports weird column names, such as " " + DT::datatable( + tibble::tibble(` ` = logical(0)), + options = list(language = list(zeroRecords = "No variable selected."), pageLength = input$levels_table_rows) + ) + } else { + decorated_summary_table_q()[["table"]] + } + }) + + by_subject_plot_r <- reactive({ + req(decorated_by_subject_plot_q()[["by_subject_plot"]]) + }) + + # Generate output pws1 <- teal.widgets::plot_with_settings_srv( id = "summary_plot", plot_r = summary_plot_r, @@ -1249,6 +1339,8 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par width = plot_width ) + output$levels_table <- DT::renderDataTable(summary_table_r()) + pws3 <- teal.widgets::plot_with_settings_srv( id = "by_subject_plot", plot_r = by_subject_plot_r, @@ -1256,23 +1348,22 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par width = plot_width ) - final_q <- reactive({ - req(input$summary_type) - sum_type <- input$summary_type + decorated_final_q <- reactive({ + sum_type <- req(input$summary_type) if (sum_type == "Summary") { - summary_plot_q() + decorated_summary_plot_q() } else if (sum_type == "Combinations") { - combination_plot_q() + decorated_combination_plot_q() } else if (sum_type == "By Variable Levels") { - summary_table_q() + decorated_summary_table_q() } else if (sum_type == "Grouped by Subject") { - by_subject_plot_q() + decorated_by_subject_plot_q() } }) teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(final_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_final_q()))), title = "Show R Code for Missing Data" ) @@ -1308,7 +1399,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(final_q())) + card$append_src(teal.code::get_code(req(decorated_final_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index dab983f2d..28473f6c9 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -11,17 +11,46 @@ #' Specifies variable(s) to be analyzed for outliers. #' @param categorical_var (`data_extract_spec` or `list` of multiple `data_extract_spec`) optional, #' specifies the categorical variable(s) to split the selected outlier variables on. -#' -#' @templateVar ggnames "Boxplot","Density Plot","Cumulative Distribution Plot" -#' @template ggplot2_args_multi +#' @param ggplot2_args `r roxygen_ggplot2_args_param("Boxplot", "Density Plot", "Cumulative Distribution Plot")` +#' @param decorators `r roxygen_decorators_param("tm_outliers")` #' #' @inherit shared_params return #' +#' @section Decorating `tm_outliers`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `box_plot` (`ggplot2`) +#' - `density_plot` (`ggplot2`) +#' - `cumulative_plot` (`ggplot2`) +#' - `table` ([DT::datatable()]) +#' +#' Decorators can be applied to all outputs or only to specific objects using a +#' named list of `teal_transform_module` objects. +#' The `"default"` name is reserved for decorators that are applied to all outputs. +#' See code snippet below: +#' +#' ``` +#' tm_outliers( +#' ..., # arguments for module +#' decorators = list( +#' default = list(teal_transform_module(...)), # applied to all outputs +#' box_plot = list(teal_transform_module(...)), # applied only to `box_plot` output +#' density_plot = list(teal_transform_module(...)) # applied only to `density_plot` output +#' cumulative_plot = list(teal_transform_module(...)) # applied only to `cumulative_plot` output +#' table = list(teal_transform_module(...)) # applied only to `table` output +#' ) +#' ) +#' ``` +#' +#' 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.general) #' interactive <- function() TRUE #' {{ next_example }} #' @examples +#' #' # general data example #' data <- teal_data() #' data <- within(data, { @@ -71,6 +100,7 @@ #' interactive <- function() TRUE #' {{ next_example }} #' @examples +#' #' # CDISC data example #' data <- teal_data() #' data <- within(data, { @@ -81,6 +111,8 @@ #' fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) #' vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl)) #' +#' +#' #' app <- init( #' data = data, #' modules = modules( @@ -125,7 +157,8 @@ tm_outliers <- function(label = "Outliers Module", plot_height = c(600, 200, 2000), plot_width = NULL, pre_output = NULL, - post_output = NULL) { + post_output = NULL, + decorators = NULL) { message("Initializing tm_outliers") # Normalize the parameters @@ -162,6 +195,10 @@ tm_outliers <- function(label = "Outliers Module", checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + + available_decorators <- c("box_plot", "density_plot", "cumulative_plot", "table") + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, names = available_decorators) # End of assertions # Make UI args @@ -172,12 +209,16 @@ tm_outliers <- function(label = "Outliers Module", categorical_var = categorical_var ) + ans <- module( label = label, server = srv_outliers, server_args = c( data_extract_list, - list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args) + list( + plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args, + decorators = decorators + ) ), ui = ui_outliers, ui_args = args, @@ -300,6 +341,28 @@ ui_outliers <- function(id, ...) { uiOutput(ns("ui_outlier_help")) ) ), + conditionalPanel( + condition = paste0("input['", ns("tabs"), "'] == 'Boxplot'"), + ui_decorate_teal_data( + ns("d_box_plot"), + decorators = select_decorators(args$decorators, "box_plot") + ) + ), + conditionalPanel( + condition = paste0("input['", ns("tabs"), "'] == 'Density Plot'"), + ui_decorate_teal_data( + ns("d_density_plot"), + decorators = select_decorators(args$decorators, "density_plot") + ) + ), + conditionalPanel( + condition = paste0("input['", ns("tabs"), "'] == 'Cumulative Distribution Plot'"), + ui_decorate_teal_data( + ns("d_cumulative_plot"), + decorators = select_decorators(args$decorators, "cumulative_plot") + ) + ), + ui_decorate_teal_data(ns("d_table"), decorators = select_decorators(args$decorators, "table")), teal.widgets::panel_item( title = "Plot settings", selectInput( @@ -319,9 +382,10 @@ ui_outliers <- function(id, ...) { ) } +# Server function for the outliers module # Server function for the outliers module srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, - categorical_var, plot_height, plot_width, ggplot2_args) { + categorical_var, plot_height, plot_width, ggplot2_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") @@ -561,7 +625,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ) ) - if (length(categorical_var) > 0) { + qenv <- if (length(categorical_var) > 0) { qenv <- teal.code::eval_code( qenv, substitute( @@ -617,7 +681,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ) } - qenv <- teal.code::eval_code( + teal.code::eval_code( qenv, substitute( expr = { @@ -645,7 +709,6 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, tidyr::pivot_longer(-categorical_var_name) %>% tidyr::pivot_wider(names_from = categorical_var, values_from = value) %>% tibble::column_to_rownames("name") - summary_table }, env = list( categorical_var = categorical_var, @@ -653,8 +716,22 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ) ) ) + } else { + within(qenv, summary_table <- data.frame()) } + # Datatable is generated in qenv to allow for output decoration + qenv <- within(qenv, { + table <- DT::datatable( + summary_table, + options = list( + dom = "t", + autoWidth = TRUE, + columnDefs = list(list(width = "200px", targets = "_all")) + ) + ) + }) + if (length(categorical_var) > 0 && nrow(qenv[["ANL_OUTLIER"]]) > 0) { shinyjs::show("order_by_outlier") } else { @@ -664,26 +741,8 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, qenv }) - output$summary_table <- DT::renderDataTable( - expr = { - if (iv_r()$is_valid()) { - categorical_var <- as.vector(merged$anl_input_r()$columns_source$categorical_var) - if (!is.null(categorical_var)) { - DT::datatable( - common_code_q()[["summary_table"]], - options = list( - dom = "t", - autoWidth = TRUE, - columnDefs = list(list(width = "200px", targets = "_all")) - ) - ) - } - } - } - ) - # boxplot/violinplot # nolint commented_code - boxplot_q <- reactive({ + box_plot_q <- reactive({ req(common_code_q()) ANL <- common_code_q()[["ANL"]] ANL_OUTLIER <- common_code_q()[["ANL_OUTLIER"]] @@ -761,7 +820,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, teal.code::eval_code( common_code_q(), substitute( - expr = g <- plot_call + + expr = box_plot <- plot_call + scale_color_manual(values = c("TRUE" = "red", "FALSE" = "black")) + labs + ggthemes + themes, env = list( @@ -771,8 +830,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, themes = parsed_ggplot2_args$theme ) ) - ) %>% - teal.code::eval_code(quote(print(g))) + ) }) # density plot @@ -823,7 +881,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, teal.code::eval_code( common_code_q(), substitute( - expr = g <- plot_call + labs + ggthemes + themes, + expr = density_plot <- plot_call + labs + ggthemes + themes, env = list( plot_call = plot_call, labs = parsed_ggplot2_args$labs, @@ -831,8 +889,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ggthemes = parsed_ggplot2_args$ggtheme ) ) - ) %>% - teal.code::eval_code(quote(print(g))) + ) }) # Cumulative distribution plot @@ -925,7 +982,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, teal.code::eval_code( qenv, substitute( - expr = g <- plot_call + + expr = cumulative_plot <- plot_call + geom_point(data = outlier_points, aes(x = outlier_var_name, y = y, color = is_outlier_selected)) + scale_color_manual(values = c("TRUE" = "red", "FALSE" = "black")) + labs + ggthemes + themes, @@ -937,40 +994,63 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ggthemes = parsed_ggplot2_args$ggtheme ) ) - ) %>% - teal.code::eval_code(quote(print(g))) + ) }) - final_q <- reactive({ - req(input$tabs) - tab_type <- input$tabs - result_q <- if (tab_type == "Boxplot") { - boxplot_q() - } else if (tab_type == "Density Plot") { - density_plot_q() - } else if (tab_type == "Cumulative Distribution Plot") { - cumulative_plot_q() - } - # used to display table when running show-r-code code - # added after the plots so that a change in selected columns doesn't affect - # brush selection. - teal.code::eval_code( - result_q, - substitute( - expr = { - columns_index <- union( - setdiff(names(ANL_OUTLIER), c("is_outlier_selected", "order")), - table_columns - ) - ANL_OUTLIER_EXTENDED[ANL_OUTLIER_EXTENDED$is_outlier_selected, columns_index] - }, - env = list( - table_columns = input$table_ui_columns - ) - ) + current_tab_r <- reactive({ + switch(req(input$tabs), + "Boxplot" = "box_plot", + "Density Plot" = "density_plot", + "Cumulative Distribution Plot" = "cumulative_plot" ) }) + decorated_q <- mapply( + function(obj_name, q) { + srv_decorate_teal_data( + id = sprintf("d_%s", obj_name), + data = q, + decorators = select_decorators(decorators, obj_name), + expr = reactive({ + substitute( + expr = { + columns_index <- union( + setdiff(names(ANL_OUTLIER), c("is_outlier_selected", "order")), + table_columns + ) + ANL_OUTLIER_EXTENDED[ANL_OUTLIER_EXTENDED$is_outlier_selected, columns_index] + print(.plot) + }, + env = list(table_columns = input$table_ui_columns, .plot = as.name(obj_name)) + ) + }), + expr_is_reactive = TRUE + ) + }, + rlang::set_names(c("box_plot", "density_plot", "cumulative_plot")), + c(box_plot_q, density_plot_q, cumulative_plot_q) + ) + + decorated_final_q_no_table <- reactive(decorated_q[[req(current_tab_r())]]()) + + decorated_final_q <- srv_decorate_teal_data( + "d_table", + data = decorated_final_q_no_table, + decorators = select_decorators(decorators, "table"), + expr = table + ) + + output$summary_table <- DT::renderDataTable( + expr = { + if (iv_r()$is_valid()) { + categorical_var <- as.vector(merged$anl_input_r()$columns_source$categorical_var) + if (!is.null(categorical_var)) { + decorated_final_q()[["table"]] + } + } + } + ) + # slider text output$ui_outlier_help <- renderUI({ req(input$method) @@ -1019,22 +1099,22 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, } }) - boxplot_r <- reactive({ + box_plot_r <- reactive({ teal::validate_inputs(iv_r()) - boxplot_q()[["g"]] + req(decorated_q$box_plot())[["box_plot"]] }) density_plot_r <- reactive({ teal::validate_inputs(iv_r()) - density_plot_q()[["g"]] + req(decorated_q$density_plot())[["density_plot"]] }) cumulative_plot_r <- reactive({ teal::validate_inputs(iv_r()) - cumulative_plot_q()[["g"]] + req(decorated_q$cumulative_plot())[["cumulative_plot"]] }) box_pws <- teal.widgets::plot_with_settings_srv( id = "box_plot", - plot_r = boxplot_r, + plot_r = box_plot_r, height = plot_height, width = plot_width, brushing = TRUE @@ -1080,16 +1160,20 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ANL_OUTLIER_EXTENDED <- common_code_q()[["ANL_OUTLIER_EXTENDED"]] ANL <- common_code_q()[["ANL"]] - plot_brush <- if (tab == "Boxplot") { - boxplot_r() - box_pws$brush() - } else if (tab == "Density Plot") { - density_plot_r() - density_pws$brush() - } else if (tab == "Cumulative Distribution Plot") { - cumulative_plot_r() - cum_density_pws$brush() - } + plot_brush <- switch(current_tab_r(), + box_plot = { + box_plot_r() + box_pws$brush() + }, + density_plot = { + density_plot_r() + density_pws$brush() + }, + cumulative_plot = { + cumulative_plot_r() + cum_density_pws$brush() + } + ) # removing unused column ASAP ANL_OUTLIER$order <- ANL$order <- NULL @@ -1217,7 +1301,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(final_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_final_q()))), title = "Show R Code for Outlier" ) @@ -1239,7 +1323,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, } card$append_text("Plot", "header3") if (tab_type == "Boxplot") { - card$append_plot(boxplot_r(), dim = box_pws$dim()) + card$append_plot(box_plot_r(), dim = box_pws$dim()) } else if (tab_type == "Density Plot") { card$append_plot(density_plot_r(), dim = density_pws$dim()) } else if (tab_type == "Cumulative Distribution Plot") { @@ -1249,7 +1333,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(final_q())) + card$append_src(teal.code::get_code(req(decorated_final_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/tm_t_crosstable.R b/R/tm_t_crosstable.R index 47d84bcfd..5c8621fc3 100644 --- a/R/tm_t_crosstable.R +++ b/R/tm_t_crosstable.R @@ -19,12 +19,21 @@ #' @param show_total (`logical(1)`) #' Indicates whether to show total column. #' Defaults to `TRUE`. +#' @param decorators `r roxygen_decorators_param("tm_t_crosstable")` #' #' @note For more examples, please see the vignette "Using cross table" via #' `vignette("using-cross-table", package = "teal.modules.general")`. #' #' @inherit shared_params return #' +#' @section Decorating `tm_t_crosstable`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `table` (`ElementaryTable` - 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.general) #' interactive <- function() TRUE @@ -134,7 +143,8 @@ tm_t_crosstable <- function(label = "Cross Table", show_total = 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_crosstable") # Requires Suggested packages @@ -158,6 +168,9 @@ tm_t_crosstable <- function(label = "Cross Table", checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) checkmate::assert_class(basic_table_args, classes = "basic_table_args") + + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, null.ok = TRUE, "plot") # End of assertions # Make UI args @@ -167,7 +180,8 @@ tm_t_crosstable <- function(label = "Cross Table", label = label, x = x, y = y, - basic_table_args = basic_table_args + basic_table_args = basic_table_args, + decorators = decorators ) ans <- module( @@ -184,6 +198,7 @@ tm_t_crosstable <- function(label = "Cross Table", # UI function for the cross-table module ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, post_output, ...) { + args <- list(...) ns <- NS(id) is_single_dataset <- teal.transform::is_single_dataset(x, y) @@ -221,7 +236,8 @@ ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, p checkboxInput(ns("show_percentage"), "Show column percentage", value = show_percentage), checkboxInput(ns("show_total"), "Show total column", value = show_total) ) - ) + ), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "plot")) ), forms = tagList( teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code") @@ -232,7 +248,7 @@ ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, p } # Server function for the cross-table module -srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, basic_table_args) { +srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, 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") @@ -351,7 +367,7 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, teal.code::eval_code( substitute( expr = { - lyt <- basic_tables %>% + table <- basic_tables %>% split_call %>% # styler: off rtables::add_colcounts() %>% tern::analyze_vars( @@ -387,19 +403,25 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, substitute( expr = { ANL <- tern::df_explicit_na(ANL) - tbl <- rtables::build_table(lyt = lyt, df = ANL[order(ANL[[y_name]]), ]) - tbl + table <- rtables::build_table(lyt = table, df = ANL[order(ANL[[y_name]]), ]) }, env = list(y_name = y_name) ) ) }) - output$title <- renderText(output_q()[["title"]]) + decorated_output_q <- srv_decorate_teal_data( + id = "decorator", + data = output_q, + decorators = select_decorators(decorators, "plot"), + expr = table + ) + + output$title <- renderText(req(decorated_output_q())[["title"]]) table_r <- reactive({ req(iv_r()$is_valid()) - output_q()[["tbl"]] + req(decorated_output_q())[["table"]] }) teal.widgets::table_with_settings_srv( @@ -409,7 +431,7 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(output_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_output_q()))), title = "Show R Code for Cross-Table" ) @@ -428,7 +450,7 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(output_q())) + card$append_src(teal.code::get_code(req(decorated_output_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) diff --git a/R/utils.R b/R/utils.R index 5876abcab..dcb0ebd17 100644 --- a/R/utils.R +++ b/R/utils.R @@ -25,7 +25,6 @@ #' with text placed before the output to put the output into context. For example a title. #' @param post_output (`shiny.tag`) optional, text or UI element to be displayed after the module's output, #' adding context or further instructions. Elements like `shiny::helpText()` are useful. -#' #' @param alpha (`integer(1)` or `integer(3)`) optional, specifies point opacity. #' - When the length of `alpha` is one: the plot points will have a fixed opacity. #' - When the length of `alpha` is three: the plot points opacity are dynamically adjusted based on @@ -278,3 +277,134 @@ assert_single_selection <- function(x, } invisible(TRUE) } + +#' Wrappers around `srv_transform_teal_data` that allows to decorate the data +#' @inheritParams teal::srv_transform_teal_data +#' @param expr (`expression` or `reactive`) to evaluate on the output of the decoration. +#' When an expression it must be inline code. See [within()] +#' Default is `NULL` which won't evaluate any appending code. +#' @param expr_is_reactive (`logical(1)`) whether `expr` is a reactive expression +#' that skips defusing the argument. +#' @details +#' `srv_decorate_teal_data` is a wrapper around `srv_transform_teal_data` that +#' allows to decorate the data with additional expressions. +#' When original `teal_data` object is in error state, it will show that error +#' first. +#' +#' @keywords internal +srv_decorate_teal_data <- function(id, data, decorators, expr, expr_is_reactive = FALSE) { + checkmate::assert_class(data, classes = "reactive") + checkmate::assert_list(decorators, "teal_transform_module") + checkmate::assert_flag(expr_is_reactive) + + missing_expr <- missing(expr) + if (!missing_expr && !expr_is_reactive) { + expr <- rlang::enexpr(expr) + } + + moduleServer(id, function(input, output, session) { + decorated_output <- srv_transform_teal_data("inner", data = data, transformators = decorators) + + reactive({ + # ensure original errors are displayed and `eval_code` is never executed with NULL + req(data(), decorated_output()) + if (missing_expr) { + decorated_output() + } else if (expr_is_reactive) { + teal.code::eval_code(decorated_output(), expr()) + } else { + teal.code::eval_code(decorated_output(), expr) + } + }) + }) +} + +#' @rdname srv_decorate_teal_data +#' @details +#' `ui_decorate_teal_data` is a wrapper around `ui_transform_teal_data`. +#' @keywords internal +ui_decorate_teal_data <- function(id, decorators, ...) { + teal::ui_transform_teal_data(NS(id, "inner"), transformators = decorators, ...) +} + +#' Internal function to check if decorators is a valid object +#' @noRd +check_decorators <- function(x, names = NULL, null.ok = FALSE) { # nolint: object_name. + checkmate::qassert(null.ok, "B1") + + check_message <- checkmate::check_list( + x, + null.ok = null.ok, + names = "named" + ) + + if (!is.null(names)) { + check_message <- if (isTRUE(check_message)) { + out_message <- checkmate::check_names(names(x), subset.of = c("default", names)) + # see https://github.com/insightsengineering/teal.logger/issues/101 + if (isTRUE(out_message)) { + out_message + } else { + gsub("\\{", "(", gsub("\\}", ")", out_message)) + } + } else { + check_message + } + } + + if (!isTRUE(check_message)) { + return(check_message) + } + + valid_elements <- vapply( + x, + checkmate::test_list, + types = "teal_transform_module", + null.ok = TRUE, + FUN.VALUE = logical(1L) + ) + + if (all(valid_elements)) { + return(TRUE) + } + + "May only contain the type 'teal_transform_module' or a named list of 'teal_transform_module'." +} + +#' Internal assertion on decorators +#' @noRd +assert_decorators <- checkmate::makeAssertionFunction(check_decorators) + +#' Subset decorators based on the scope +#' +#' `default` is a protected decorator name that is always included in the output, +#' if it exists +#' +#' @param scope (`character`) a character vector of decorator names to include. +#' @param decorators (named `list`) of list decorators to subset. +#' +#' @return A flat list with all decorators to include. +#' It can be an empty list if none of the scope exists in `decorators` argument. +#' @keywords internal +select_decorators <- function(decorators, scope) { + checkmate::assert_character(scope, null.ok = TRUE) + scope <- intersect(union("default", scope), names(decorators)) + c(list(), unlist(decorators[scope], recursive = FALSE)) +} + +#' Convert flat list of `teal_transform_module` to named lists +#' +#' @param decorators (list of `teal_transform_module`) to normalize. +#' @return A named list of lists with `teal_transform_module` objects. +#' @keywords internal +normalize_decorators <- function(decorators) { + if (checkmate::test_list(decorators, "teal_transform_module", null.ok = TRUE)) { + if (checkmate::test_names(names(decorators))) { + lapply(decorators, list) + } else { + list(default = decorators) + } + } else { + decorators + } +} diff --git a/man-roxygen/ggplot2_args_multi.R b/man-roxygen/ggplot2_args_multi.R deleted file mode 100644 index dc0497942..000000000 --- a/man-roxygen/ggplot2_args_multi.R +++ /dev/null @@ -1,7 +0,0 @@ -#' @param ggplot2_args (`ggplot2_args`) optional, object created by [`teal.widgets::ggplot2_args()`] -#' with settings for all the plots or named list of `ggplot2_args` objects for plot-specific settings. -#' The argument is merged with options variable `teal.ggplot2_args` and default module setup. -#' -#' List names should match the following: `c("default", <%=ggnames%>)`. -#' -#' For more details see the vignette: `vignette("custom-ggplot2-arguments", package = "teal.widgets")`. diff --git a/man/normalize_decorators.Rd b/man/normalize_decorators.Rd new file mode 100644 index 000000000..257342765 --- /dev/null +++ b/man/normalize_decorators.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{normalize_decorators} +\alias{normalize_decorators} +\title{Convert flat list of \code{teal_transform_module} to named lists} +\usage{ +normalize_decorators(decorators) +} +\arguments{ +\item{decorators}{(list of \code{teal_transform_module}) to normalize.} +} +\value{ +A named list of lists with \code{teal_transform_module} objects. +} +\description{ +Convert flat list of \code{teal_transform_module} to named lists +} +\keyword{internal} diff --git a/man/select_decorators.Rd b/man/select_decorators.Rd new file mode 100644 index 000000000..2c7403dca --- /dev/null +++ b/man/select_decorators.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{select_decorators} +\alias{select_decorators} +\title{Subset decorators based on the scope} +\usage{ +select_decorators(decorators, scope) +} +\arguments{ +\item{decorators}{(named \code{list}) of list decorators to subset.} + +\item{scope}{(\code{character}) a character vector of decorator names to include.} +} +\value{ +A flat list with all decorators to include. +It can be an empty list if none of the scope exists in \code{decorators} argument. +} +\description{ +\code{default} is a protected decorator name that is always included in the output, +if it exists +} +\keyword{internal} diff --git a/man/srv_decorate_teal_data.Rd b/man/srv_decorate_teal_data.Rd new file mode 100644 index 000000000..18201124e --- /dev/null +++ b/man/srv_decorate_teal_data.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{srv_decorate_teal_data} +\alias{srv_decorate_teal_data} +\alias{ui_decorate_teal_data} +\title{Wrappers around \code{srv_transform_teal_data} that allows to decorate the data} +\usage{ +srv_decorate_teal_data(id, data, decorators, expr, expr_is_reactive = FALSE) + +ui_decorate_teal_data(id, decorators, ...) +} +\arguments{ +\item{id}{(\code{character(1)}) Module id} + +\item{data}{(\verb{reactive teal_data})} + +\item{expr}{(\code{expression} or \code{reactive}) to evaluate on the output of the decoration. +When an expression it must be inline code. See \code{\link[=within]{within()}} +Default is \code{NULL} which won't evaluate any appending code.} + +\item{expr_is_reactive}{(\code{logical(1)}) whether \code{expr} is a reactive expression +that skips defusing the argument.} +} +\description{ +Wrappers around \code{srv_transform_teal_data} that allows to decorate the data +} +\details{ +\code{srv_decorate_teal_data} is a wrapper around \code{srv_transform_teal_data} that +allows to decorate the data with additional expressions. +When original \code{teal_data} object is in error state, it will show that error +first. + +\code{ui_decorate_teal_data} is a wrapper around \code{ui_transform_teal_data}. +} +\keyword{internal} diff --git a/man/tm_a_pca.Rd b/man/tm_a_pca.Rd index ac4f506ba..101f5d6e6 100644 --- a/man/tm_a_pca.Rd +++ b/man/tm_a_pca.Rd @@ -16,7 +16,8 @@ tm_a_pca( alpha = c(1, 0, 1), size = c(2, 1, 8), pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -34,9 +35,7 @@ specifying columns used to compute PCA.} \item{ggtheme}{(\code{character}) optional, \code{ggplot2} theme to be used by default. Defaults to \code{"gray"}.} -\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} -with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. -The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. +\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. List names should match the following: \code{c("default", "Elbow plot", "Circle plot", "Biplot", "Eigenvector plot")}. @@ -72,6 +71,12 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like \code{shiny::helpText()} 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_a_pca}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -82,7 +87,40 @@ ways of visualizing the outcomes, including elbow plot, circle plot, biplot, and Additionally, it enables dynamic customization of plot aesthetics, such as opacity, size, and font size, through UI inputs. } +\section{Decorating \code{tm_a_pca}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{elbow_plot} (\code{ggplot2}) +\item \code{circle_plot} (\code{ggplot2}) +\item \code{biplot} (\code{ggplot2}) +\item \code{eigenvector_plot} (\code{ggplot2}) +} + +Decorators can be applied to all outputs or only to specific objects using a +named list of \code{teal_transform_module} objects. +The \code{"default"} name is reserved for decorators that are applied to all outputs. +See code snippet below: + +\if{html}{\out{
}}\preformatted{tm_a_pca( + ..., # arguments for module + decorators = list( + default = list(teal_transform_module(...)), # applied to all outputs + elbow_plot = list(teal_transform_module(...)), # applied only to `elbow_plot` output + circle_plot = list(teal_transform_module(...)) # applied only to `circle_plot` output + biplot = list(teal_transform_module(...)) # applied only to `biplot` output + eigenvector_plot = list(teal_transform_module(...)) # applied only to `eigenvector_plot` output + ) +) +}\if{html}{\out{
}} + +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{ + # general data example data <- teal_data() data <- within(data, { @@ -113,6 +151,7 @@ if (interactive()) { shinyApp(app$ui, app$server) } + # CDISC data example data <- teal_data() data <- within(data, { @@ -148,14 +187,14 @@ if (interactive()) { \section{Examples in Shinylive}{ \describe{ \item{example-1}{ - \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6uoxwAI6CtNXsPqKkxNREjIoQlY4AygCCjNUtonG6fYPDpKJKAL5dSmioYyp57BX+GboAvJtBuBt8QiKju0fCYuvdlbqkMIlQiagEqRs3ugpgAAoAwv2fB2u7xiOz2jzCpGYGkSolQcAIV3ewIy0HgoM+EyGYmmALeSNEcBEGlBBKJpBhcIReKRugI+SItAIYlBWhYtCg9BEiTpDKZokRNKRKVBKWAwAxAyxI0+AF0ZaUqWAALKCRj8GQAj5gfqiURQYSkTUYxj0KAQL5EVBGsBYNBwT5dQU3OSAp2VUnw8j8UGKlVqjV4LU6vUGh2ut0wA20SJ6XYOFzU53hmkmWjUciMUEAOUcABlc4nHc6Nl0urQTLp2CoM+pNDobLZytdRIUIKx+uh2EsACT1Uo9gmMHSdOZKMCzGVAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokrcQAxLqkQ11XfxQpFC6cAAesKgiSoHBBsZc1AD6sVA2MUEhRroA7rSkABYq7Km4uiBKurqMcACOgrQ17L6ipMTURIyKEFWOAMoAgow1raLxuv1DI6SiSgC+3UpoqOMq+eyVAZm6ALxbwbibfEIiY3vHwmIbPVW6pDBJUEmoBGmbt7oKYAAKAMIDX0ONw+sV2+ye4VIzA0SVEqDgBGuHxBmWg8DBX0mwzEM0B72RojgIg0YMJxNIsPhiPxyN0BAKRFoBDEYK0LFoUHoIiS9MZzNESNpyNSYNSwGAmMG2NGXwAurKytSwABZQSMfgyQGfMADUSiKDCUhazGMehQCDfIioY1gLBoOBfbpC25yIHOqpkhHkfhgpWq9WavDa3X6w2Ot3umCG2hRPR7BwuGkuiO0ky0ajkRhggByjgAMnmk06XZtut1aCZdOwVJn1JodDZbBUbqIihBWAN0OxlgASBplXuExg6LrzJRgOayoA}{Open in Shinylive} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ - \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXQGEAIgEkAZS9dfihSKF04AA9YVBElUPCDYy5qAH1EqBsEsIijXQB3WlIACxV2TNxdECVdXUY4AEdBWgb2CDFSYmoiRkUIOoBBHwCAGWT64bGlAF9+gCsiFTSAazhWUQrc23z+OBMoYVI0gn5aUQI0xeW1jeBoeE3MuQBdN2h0CZVi9lqQ3N0AF5-uFcH8+EIRKIgboIcIxL8BnVdKQYGkoGlUAQsn9kboFGAAApeQYEsFIvGJGGZNLRUjMDRpUSoOAERF4ym5B56YEEqajMm4jmiOAiDQwkVi47M1nsjl4gglJYEMQwrQsWhQegiE5K2gqzZC+V1TLU3LAYB8kYCsAvF5VNkEgBCAFksABpLAARjJ+LAgwA4q48H7nAB5AI+ACaBP6xuRcnJ8bqktZ5H4MMdYFdHu9vr5QdjSeTMCOtDiPPsTlcFI5iaNyJMtGo5EYMIAco5RgLa3U4wm-v1+rQTLp2CpW+pNDobLYakjRGUIKxBuh2GhUAASFpVDebkWMHR9WZKMAzF5AA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokrcQAxLoDCAEQCSAMreuvxQpFC6cAAesKgiSmERBsZc1AD6SVA2ieGRRroA7rSkABYq7Fm4uiBKurqMcACOgrSN7BBipMTURIyKEPUAgr6BADIpDSPjSgC+AwBWRCrpANZwrKKVebYF-HAmUMKk6QT8tKIE6Usr65vA0PBbWXIAuu5oqJMqJex1oXldABeAERXD-PhCESiYG6SHCMR-Qb1XSkGDpKDpVAEbL-FG6BRgAAK3iGhPByPxSVhWXSMVIzA06VEqDgBCR+KpeUeehBhOmY3JeM5ojgIg0sNF4pOLLZHM5+IIpWWBDEsK0LFoUHoIlOytoqq2woV9SyNLywGA-NGgrAr1e1XZhIAQgBZLAAaSwAEZyQSwEMAOKuPD+5wAeUCvgAmoSBiaUXIKQn6lK2eR+LCnWA3Z6fX7+cG48mUzBjrR4rz7E5XJTOUnjSiTLRqORGLCAHKOMaCuv1eOJ-4DAa0Ey6dgqNvqTQ6Gy2WrI0TlCCsIbodifAAkrWqW9FjB0-TmSjAs1eQA}{Open in Shinylive} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_a_regression.Rd b/man/tm_a_regression.Rd index 85b3c578d..cd4621cc6 100644 --- a/man/tm_a_regression.Rd +++ b/man/tm_a_regression.Rd @@ -18,7 +18,8 @@ tm_a_regression( post_output = NULL, default_plot_type = 1, default_outlier_label = "USUBJID", - label_segment_threshold = c(0.5, 0, 10) + label_segment_threshold = c(0.5, 0, 10), + decorators = NULL ) } \arguments{ @@ -53,11 +54,9 @@ vector of \code{value}, \code{min}, and \code{max}. \item{ggtheme}{(\code{character}) optional, \code{ggplot2} theme to be used by default. Defaults to \code{"gray"}.} -\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} -with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. -The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. +\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. -List names should match the following: \verb{c("default", "Response vs Regressor", "Residuals vs Fitted", "Scale-Location", "Cook's distance", "Residuals vs Leverage"", "Cook's dist vs Leverage")}. +List names should match the following: \code{c("default", "Response vs Regressor", "Residuals vs Fitted", "Scale-Location", "Cook's distance", "Residuals vs Leverage", "Cook's dist vs Leverage")}. For more details see the vignette: \code{vignette("custom-ggplot2-arguments", package = "teal.widgets")}.} @@ -96,6 +95,12 @@ It can take the following forms: It takes the form of \code{c(value, min, max)} and it is passed to the \code{value_min_max} argument in \code{teal.widgets::optionalSliderInputValMinMax}. }} + +\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_a_regression}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -110,7 +115,20 @@ visualize residuals, and identify outliers. For more examples, please see the vignette "Using regression plots" via \code{vignette("using-regression-plots", package = "teal.modules.general")}. } +\section{Decorating \code{tm_a_regression}}{ + + +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{ + # general data example data <- teal_data() data <- within(data, { @@ -194,14 +212,14 @@ if (interactive()) { \section{Examples in Shinylive}{ \describe{ \item{example-1}{ - \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6uoxwAI6CtNXsPqKkxNREjIoQlQDCAPIATHG6-QNKAL5dSmiowyp57BX+GboAvMtBuEt8QiKia7o7wmKL3ZW6pDCJUInVEtWiolYQp+fn1FD0cH7rCmBYcHuYieJD+WzObweqBIoj06xSiTCpGYGkSolQcAIrze5xS0HgBz+ozBSxxulhIg0BwpmNIaIxWNJZN0Hy+P10fwAyt9abotCxaJ8RIgSRDmQR8kRaAQxISwIJUEEANZwUXM840jRwfhyhXK1V4JlkmDCTSROG6ABiAEEADKc5zg9WVEy0ULag4OFxG85dMlyJ04u4PUQdA4IpEounozHYsl42AWomDNXMzWkak81Exxlisms75y7mUjP8xiC+h7EWGvM4iVSmX7dZlisiRL16UnFLAYDJsZgAC6A9KjMIJAIYI5YDs1UC8DIfzkAZ9b3THt+Y4sqfVJuoZpEnqcjpX51d7p16xt9tctcqfpx97vSy6XVoJl07BU5Cj2jgNls5RnKIhQQKw1roOwMwACT1KU0GwowOidBMShgOMA5AA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokrcQAxLqkQ11XfxQpFC6cAAesKgiSoHBBsZc1AD6sVA2MUEhRroA7rSkABYq7Km4uiBKurqMcACOgrQ17L6ipMTURIyKEFUAwgDyAEzxugODSgC+3UpoqCMq+eyVAZm6ALwrwbjLfEIiouu6u8JiSz1VuqQwSVBJNRI1oqJWEGcXF9RQ9HD+GwpgWDgDzEzxI-2253ej1QJFEeg2qSS4VIzA0SVEqDgBDe7wuqWg8EO-zG4OWuN0cJEGkOlKxpHRmOxZPJuk+31+un+AGUfnTdFoWLQviJEKTISyCAUiLQCGIiWBBKhggBrOBilkXWkaOD8eWKlVqvDM8kwYSaKLw3QAMQAggAZLnOCEaqomWhhHWHBwuY0XbrkuTO3H3R6iTqHRHI1H0jFYnHk-GwS3Eobqlla0g03lo2NM8Xktk-eU8qmZgWMIX0faio353GS6Wyg4bcuVkRJBsy06pYDAFPjMAAXUHZSZhBIBHBnLAdhqQXgZH+ckDvveGc9f3HFjTGtN1HNIi9Tidq4ubo9uo2todrjrVX9uIf9+W3W6tBMunYKnI0e0cBstgVOcohFBArA2ug7CzAAJA0ZQwXCjA6F0kxKGAEyDkAA}{Open in Shinylive} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXQGEAIgEkAZS9dfihSKF04AA9YVBElUPCDYy5qAH1EqBsEsIijXQB3WlIACxV2TNxdECVdXUY4AEdBWgb2CDFSYmoiRkUIOoBBHwCAGWT64bGlAF9+gCsiFTSAazhWUQrc23z+OBMoYVI0gn5aUQI0xeW1jeBoeE3MuQBdN2h0CZVi9lqQ3N0AF5-uFcH8+EIRKIgboIcIxL8BnVdKQYGkoGkGhIGqJRFYIIjkcjqFB6HBqDCFGAsHBsWI8SQqWCkUScagSKI9MDMmloqRmBo0qJUHACISicjMg8uboqVNRky-hLdJyRBoYarRcdhaLxcq6iSyRTgVSAuStbotCxaKSRIhFSz9QQSksCGJKWAAEIAWSwAGksABGB365GajRwfgen3+oMh0Owo60OIygBig1GAWczITploUUjMIcLiVEv6yrkOYlWJxol6MJ5fIF2pFYtLRKlsBlcpGCrw7bD5vVwPDLd1A6JhvJHrNatIluttrE9v7juVztd7uBVsYNvoIhOLtobqeuWAwB70zALxeVTbYEGAHFXHhZWAswANJlvrCDLwvuRKwnQc50LE0H2feNQxgJMUyLJxs2AuoTHzMDdHTTNXDXZFyzLUtcP6fpaBMXR2BUchm20OAbFsGokVEMoIFYQZ0HYNBUAAEhaKp2I4zlGB0PpZiUMAZheIA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_data_table.Rd b/man/tm_data_table.Rd index 3d105c6c0..ca1db1ea6 100644 --- a/man/tm_data_table.Rd +++ b/man/tm_data_table.Rd @@ -13,7 +13,8 @@ tm_data_table( scrollX = TRUE), server_rendering = FALSE, pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -46,6 +47,12 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like \code{shiny::helpText()} 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_data_table}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -61,6 +68,18 @@ Configure the \code{DT.TOJSON_ARGS} option via \code{options(DT.TOJSON_ARGS = list(na = "string"))} before running the module. Note though that sorting of numeric columns with \code{NA}/\code{Inf} will be lexicographic not numerical. } +\section{Decorating \code{tm_data_table}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{table} (\code{\link[DT:datatable]{DT::datatable()}}) +} + +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{ # general data example data <- teal_data() @@ -110,13 +129,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6uoxwAI6CtNXsPqKkxNREjIoQlQ20onG6vaJKAL5dSmioAyp57BX+GboAvAtBuPN8QiL9K5vCYnPdlbqkMMkZiUH0IofHx1ostFDXYomicCIacPzLunQttzuxyGvwIczAAGU4KhuBgADIUCQFBR4XQoqEwngAdVo-GRqJRAAU4EEeAiIEj8ijSkSSbCcXiqQTIag4ARaGIUV0gbo5Osjnc8YkWBIdn8+qR2AQ0JoSL8UQBJLAKiH2Z4iXQAYRlVggXPmlW5vKUXVoJl07BU5GYlh0Nls5SOokKEFYAEF0OxJgASeqlH3vRg6TqjJRgEYAXSAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXQGEAIgEkAZS9dfihSKF04AA9YVBElUPCDYy5qAH1EqBsEsIijXQB3WlIACxV2TNxdECVdXUY4AEdBWgb2CDFSYmoiRkUIOoBBHwCAGWT64bGlAF9+gCsiFTSAazhWUQrc23z+OBMoYVI0gn5aUQI0xeW1jeBoeE3MuQBdN2h0CZVi9lqQ3N0AF5-uFcH8+EIRKIgboIcIxL8BnVdKQYBlcmlwvQRIjkcitCxaFBsWI0qI4CINHB+DC6KJSOwpuNgQRfmAAnZHD4AJp+HwKPC6AWOAKOABCACk+QKqgLRZLpYK5X47M5FbKwIMAOKuJXs5wADQFcjkYKReP4xxYEmhwLpDIIaE0JBhAqZ9mJIm8TqsEGNfzq-UDSn6tBMunYKnIzEsOhsthqSNEZQgrEG6HYaFQABIWlUs9nyYwdH1ZkowDMXkA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_file_viewer.Rd b/man/tm_file_viewer.Rd index cf3b5cdd3..a1617b9db 100644 --- a/man/tm_file_viewer.Rd +++ b/man/tm_file_viewer.Rd @@ -54,8 +54,8 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqX8opKAeNdqAfQ8vG3dPbyNdAHdaUgALFXYgqFxdECVdXSSfTLCME2Z4dgBGRQgAX1KlNFRslRj2dJyvXQBeJuTGviERUVbdLuExBogMjNIYfxNaEX8tWjhImWHR0ZVUQVJ-VE9YvrpRUmWV0ZMian4ZPtFWA7gYPOm4BrBRWFQZqZ6FPF1tggBrKBSPrfPy8ASDcRSCBqajfOS4RrHX4QCRXG7ke6fJ7fV4wd5wSaPUQAejxBKJIgwqFR3xSf0BwLaoLg3HB3TEkmksnhiJGyN0pAAHqR0bcsY9nuSPsSyW8ZVThaQ6b91Iy9MywGCBj0uTCeWAEUjjoJGNQQWBYqRSKhRIgSSSTB5JEQtI7ZfxGIIJKT1vR9rE4PwSQAFIiMLz+uCGAAiRAIgngZEMADFwzBPIYAMqoOAEWhTAieKwQcSofgmb7GjKlFa13SlUoF3TsFTkZiWHQ2WxpfmieIQVgAQXQ7GqABJBLQUhPRDIdIxSmUlGAygBdIA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_front_page.Rd b/man/tm_front_page.Rd index 35b1c3e9d..7da5acb05 100644 --- a/man/tm_front_page.Rd +++ b/man/tm_front_page.Rd @@ -85,8 +85,8 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqX8opKAeNdqAfQ8vG3dPbyNdAHdaUgALFXYgqFxdECVdXUY4AEdBWiz2CDFSYmoiRkUIDIBBABEAZQAZH0y6pvTdT1JGdjbGlIUweC8kwdsIulFSdkHqwTjywd0AXl1BgDlnertdLhhBgbAk-1EiQUYCOCXVwdFWMli4TQJdUbBKgF9KgCsiFX8ANZwViiRJhcbGfhwExQYSkfwEfi0UQEfy-f5AkHAaDwUFJOQAXTcZCg9BE-gAjC0khgTMx4OwAJIQExEFa6AgzMDVA5rMAAITGKTscAAHqR2ZzZrzBoL3pUvGS4P4AEzUsK0+lwdgAAwAwkRqIIYFUKTrJVy9TKwLUhbp9YbjVUVebVpyAKwYd0pABsGB9chSDqNJt0AGZXRyuTy8Hy5XIFaTyWH1V5NbBtczWRbBq5Y4MAGJ2kXinNgADi1oAEmNKkpFeSVKh5i1JtMOoM7Em9BTrrtu5TcB2wF2lboVX2G8qVUOqnzRyJw5OB2GlHXoOgWioYjM50l2UlZxk+EIRKJ2SfhGJdxkMqQYP46SR4agoFIb7eMo8oFDGP5yKWbofp+GSDIyMCoOUXhkLoKisowMCeFYEB9mBEoEFAVQSGyjxZBgBwdCBfIAPJxDIsEsuUiGaCQqFgHqmG6Nhui4XA+FgIRt6Bpxd7dueqxTv4TbzEeIE-kiNHQAEXgSPxuhVnYACyjTRvwEnIdw8lKc05S6KI8QQKw-ayUxOEyHo+hMAAfEKPGmEQRCkBAjliGWAAadHIrsjymPkUz2Y5znkNaACasHnmRelwMQED8AFTkubZc6fvpRCRP4ww-mE7IOC4nGVBk3Fzt+v7sjJogACSxBSXL1LAqCLtU6B0BhklJRkrIuYwZVvpVqDRs1tCtch8UyEl660CYujsCo5DMJYOg2LYaRzvpKisE1-VoKgFV5Ck20VaIMg6BUSgfEoYAfASQA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_g_association.Rd b/man/tm_g_association.Rd index c239f6051..4ca13c313 100644 --- a/man/tm_g_association.Rd +++ b/man/tm_g_association.Rd @@ -17,7 +17,8 @@ tm_g_association( "void"), pre_output = NULL, post_output = NULL, - ggplot2_args = teal.widgets::ggplot2_args() + ggplot2_args = teal.widgets::ggplot2_args(), + decorators = NULL ) } \arguments{ @@ -50,13 +51,17 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like \code{shiny::helpText()} are useful.} -\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} -with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. -The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. +\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. List names should match the following: \code{c("default", "Bivariate1", "Bivariate2")}. For more details see the vignette: \code{vignette("custom-ggplot2-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_g_association}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -70,6 +75,18 @@ It supports configuring the appearance of the plots, including themes and whethe For more examples, please see the vignette "Using association plot" via \code{vignette("using-association-plot", package = "teal.modules.general")}. } +\section{Decorating \code{tm_g_association}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{plot} (\code{grob} created with \code{\link[ggplot2:ggplotGrob]{ggplot2::ggplotGrob()}}) +} + +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{ # general data example data <- teal_data() @@ -159,13 +176,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6uoxwAI6CtNXsPqKkxNREjIoQlQDCAPIATHG6-QMVpuqkHaLD0PCi7ABitNTkjOy0og4upVpokRyjpZsYJpMdpe0StATc7ACMADJyL129g8BnGtMAusPU+2ohw+XymjFEP1KUHEBHyLEmMi6AF8ukp9sMVHl2OMUroALz+DK4cZ8IQiGYE0nCMTY7qVXSkGCJCSJaGiIgEWiBKwQWn0+nVEz4wlBRJhUjMDSJUSoOAEPn8+kpOZ6AkKMCjdXEumK3SiOAiDTC-WG0jS2Xy8a6yoA+gG4XqgDKBrlpF0e0YXPoIkQWqt1thRBuYmFHq9IkSgeDCxSwGA6s1YB+kN0lrAAAUAWQtbp1XZWLKc3nqoF4NmwC9tdb6SbXXB+A6M1nSH6ddaTLRQvXhYsAIKPR2uNv8t6KuRVxUeikiqBi0ISybmuUK3XK2Cq3Mawat6u1o0EvdmmXL-26232tVgZ2m90scNiX14U+KqMEEMEsNQb1wSP5INvmMMjjBNtyTFM00zKBy1KPMCzgIswDsEtGQoFsK3HZ9+UPbtLyQuBS1Qndq10GBhE0SIN22ZwJ2rDsuwbAk+wHIdq1HEd-VHLouloIUNlUSVNB0GxbHKOlREKCBWF7dB2H2AASeooXQOT9UYHROiUJElDAJEfiAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXQGEAIgEkAZS9dfihSKF04AA9YVBElUPCDYy5qAH1EqBsEsIijXQB3WlIACxV2TNxdECVdXUY4AEdBWgb2CDFSYmoiRkUIOoBBHwCAGWT64bGlAF9+gCsiFTSAazhWUQrc23z+OBMoYVI0gn5aUQI0xeW1jeBoeE3MuQBdN2h0CZVi9lqQ3N0AF5-uFcH8+EIRKIgboIcIxL8BnVdKQYGkJGkoKJREQCLQwlYIIjkciGiYYZk0tFSMwNGlRKg4ARiSTkZkHnpgQowFNRtywUjWbpRHARBoYSKxccGUyWUK6tQoPRRTDuQFRUzSLotCx8fQRIh+X95boCCUlgQxDCdYw9SITubaJbNsaTSCoMBgNzedyXi8BW7kcy1c4ABr83TcrCDLyuPCRsBeADyjgAcg4AJoR71YACy2bAAQcgzsgwAjAWi9HSwAmAt+Ox2ABifPj3IAQrmsABpLB1sD9QNyANuyWauD8VVgaOxo2C+UmWhRCcwpuDUYBVzzkmD1nD111G3Q4GU6m06WM4Pbtm5DlTn14A-Isfi4Evi+yp8kxXK6hT9VStqupKlChqPteJJmhaVrAjadpwA60EuhBrKZJ63ojK2fojoGwaFmGBYznGVTcsmaaZgWgx5pWxalhWbaFrRgz9iRYANs2rasZ2PZ9tyu4mvuKF1O+K5cmA3G9ixX7IjARy0HEnL2E4zg4QuS6iboa4bluAlPvxui7v0-S0OS7AqOQ57aHANi2DUSKiGUECsIM6DsGgqAACQtFU7keSKjA6H0sxKGAMwvEAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_g_bivariate.Rd b/man/tm_g_bivariate.Rd index cce2711a0..177b714a1 100644 --- a/man/tm_g_bivariate.Rd +++ b/man/tm_g_bivariate.Rd @@ -25,7 +25,8 @@ tm_g_bivariate( ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"), ggplot2_args = teal.widgets::ggplot2_args(), pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -100,6 +101,12 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like \code{shiny::helpText()} 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_bivariate}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -115,6 +122,18 @@ This is a general module to visualize 1 & 2 dimensional data. For more examples, please see the vignette "Using bivariate plot" via \code{vignette("using-bivariate-plot", package = "teal.modules.general")}. } +\section{Decorating \code{tm_g_bivariate}}{ + + +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{ # general data example data <- teal_data() @@ -228,13 +247,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6uoxwAI6CtNXsPqKkxNREjIoQlQDCAPIATHH+GRgmzPDs-QNdAL5dSmiowyp57BUjsQC8m1C4G3xCIqK6O6QwiRKJ9NostIFw692VuqGnu4lhpMwaiaKocAITxeLxS0Hg7wUYGmUP2zxBojgIg070RyNIfwBQI2IMq1Cg9CRkLAAGUkYDSLotHcCSJELCcbiCPkiLQCGJ3tTGPd6CJEszWezRMUMsBgFCYWAALpSuRw3EvNEUuD8YnECwM+G4ky0UIq94AMQAggAZEmuLWVLoguWM1jvFKfULfdQY-6A4G4sGwPQ7CWDTUKpUonbBt1Yz0K-GEvx+0nklFcnl0wMK3QCtkcnZJ2lwfkszPClJi-0DKEy22WxUJ8iquOCVBBADWcFTCpgwk0kV9umNZuc8rTOr1dd7pvNjKtjMrIMYRGyiRM6jglJ2jq+P3DHsnu3BPdLber6NRNcx26reIJRLjZOPOd5cHpeB3lQzQs5NIf+cFYhFQRL0IBtKsqDkGNb6nGdisACh4gsOEFjv2O7Wi8M4vG0i7LquHwbq6Z7YlW3oQnGkqgUeFInui+GRri0bXroUK3hR94ps+F7pgW77Zp+fJvr+xbioBZbAWhYHoghUJ2NUgTwGQsEvPBo59hOVYoVOzxdF0tAmLo7AqOQm7aI8ci2OUzyiIUECsEa6DsEsAAk9SlA5iKMDonRKLMShgLMUpAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXQGEAIgEkAZS9dfihSKF04AA9YVBElUPCDYy5qAH1EqBsEsIijXQB3WlIACxV2TNxdECVdXUY4AEdBWgb2CDFSYmoiRkUIOoBBHwCAGWT64bGlAF9+gCsiFTSAazhWUQrc23z+OBMoYVI0gn5aUQI0xeW1jeBoeE3MuQBdN2h0CZVi9lqQ3N0AF5-uFcH8+EIRKIgbpSDA0hI0vRtCxaGE4L8BnVdFEYZk0tFSMwNGlRKg4ARMdjsZkHnpgQowFNRoywVjqaI4CINDDOdzjmSKVTqdjqFB6FyYYyAlyKaRdFpUeKRIhWX8RboCCUlgQxDDFYw0fQRCdtbRdU9csBgIzmYyXi85GyNXU+XK4PwpUyAOKuPDqkUmWhRD0wgBig1GAVc7Ox-WpToDrDxuQJUSJ6gF5MpAbqtNg9N0tpGLP9sddsp5wLdJMFOfLovFkoZYBl-IVSuNcFVZZdmrNFv1nZNWp1Yi24WtxemYAdiYbFf5oZb0YAGmqF7oYEdaHFCxGo85nS6gyHPcCD9Hc7p43Hj3VGEQCmkDrr5cD8YTiVmhdf8-AvTtXsRRrd9dFA0ls2FDUxQlagvTbOUO0NZVuw3PtR3NPVgQNI0RwHcdMinJkS3tR17xAytyHPIsmSwABZdCT2DZddEvGMNVvOp52pboX3UOAwM-dNv0g38G3-Qtp1LCjFyQ6sqLE+s+1g5taMQnlcNQntZOxTDBxw4c4FNMdLUnG0SJnOddLkjRWMZLwAHlHAAOQcABNJiNVPVj2OvLibz+fp+loExdHYFRyG-bQMTkWwaixUQyggVhBnQdg0FQAASFoqkyrLOUYHQ+lmJQwBmF4gA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_g_distribution.Rd b/man/tm_g_distribution.Rd index 0b7cae9be..91b880f29 100644 --- a/man/tm_g_distribution.Rd +++ b/man/tm_g_distribution.Rd @@ -16,7 +16,8 @@ tm_g_distribution( plot_height = c(600, 200, 2000), plot_width = NULL, pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -37,9 +38,7 @@ Defaults to density (\code{FALSE}).} \item{ggtheme}{(\code{character}) optional, \code{ggplot2} theme to be used by default. Defaults to \code{"gray"}.} -\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} -with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. -The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. +\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. List names should match the following: \code{c("default", "Histogram", "QQplot")}. @@ -64,6 +63,12 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, 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_distribution}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -73,6 +78,38 @@ Module is designed to explore the distribution of a single variable within a giv It offers several tools, such as histograms, Q-Q plots, and various statistical tests to visually and statistically analyze the variable's distribution. } +\section{Decorating \code{tm_g_distribution}}{ + + +This module generates the following objects, which can be modified in place using decorators:: +\itemize{ +\item \code{histogram_plot} (\code{ggplot2}) +\item \code{qq_plot} (\code{data.frame}) +\item \code{summary_table} (\code{data.frame}) +\item \code{test_table} (\code{data.frame}) +} + +Decorators can be applied to all outputs or only to specific objects using a +named list of \code{teal_transform_module} objects. +The \code{"default"} name is reserved for decorators that are applied to all outputs. +See code snippet below: + +\if{html}{\out{
}}\preformatted{tm_g_distribution( + ..., # arguments for module + decorators = list( + default = list(teal_transform_module(...)), # applied to all outputs + histogram_plot = list(teal_transform_module(...)), # applied only to `histogram_plot` output + qq_plot = list(teal_transform_module(...)) # applied only to `qq_plot` output + summary_table = list(teal_transform_module(...)) # applied only to `summary_table` output + test_table = list(teal_transform_module(...)) # applied only to `test_table` output + ) +) +}\if{html}{\out{
}} + +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{ \dontshow{if (require("ggpmisc", quietly = TRUE) && require("ggpp", quietly = TRUE) && require("goftest", quietly = TRUE) && require("MASS", quietly = TRUE) && require("broom", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # general data example @@ -148,13 +185,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsBISqDC0ogT+uLpetHCk1Ky6ALz2Ts62AGTpuu7Rvv6B6BFR3rHxSSkuGVk53nkBRCbkoqRF0aUJyQ6VupnZnrVwfmAAsgCCAMrjrSVxHRVpPdX9PoP+TEREMNMxs+VdaUoAxLpSEGrUuvxQpFC6cAAesKgiSlc3BsZc1AD6b1A2r2utyMugA7rRSAALFTsP6REBKXS6HyhD7IxihJQAX0UECUaFQaJUEL8ECRf3KcMRuj4QhEonKdGapKRSNIMG+El+oVIGPogk01mprMuPO+WhYlKB3wevPUpG+olQcAILJFrL+0Hg5X8KNEEWF6tEcBEGnKxtNCqVKvYEoxUHoIm+BEhRFoBDEQz1-jkkX8AAVYtwMAAZCgSKE+w1I3Ei2O6XG42gmXTsFTkZiWHQ2WwIsm6UTQiCsUbodgEgAk3kileNjB0jFxWKUYCxAF0gA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsBISqDC0ogT+uLpetHCk1Ky6ALz2Ts62AGTpuu7Rvv6B6BFR3rHxSSkuGVk53nkBRCbkoqRF0aUJyQ6VupnZnrVwfmAAsgCCAMrjrSVxHRVpPdX9PoP+TEREMNMxs+VdaUoAxLoAwgAiAJLjJ7r8UKRQunAAHrCoIkp3DwbGXNQA+l8oDZPvdHkZdAB3WikAAWKnYQMiICUul0ozO4wAMj9shjsUoAL6KCAAKyIKn+AGs4KxRIiwbYIfw4CYoMJSP8CPxQgR-uTKTS6cBoPB6UC5ABdJRKLQsUQARlxBFhFIIYn+ojgIg0cH4fggaLljFoUHoIi5qto6vFYOAwH8+Kx-klksiBCGoywwyK-hOAHlHAA5BwATV9YHGzgAGv45HJcKjdFqdeR+OUg44sc6ICSlGhULiVDCDWigeUkUm+EIRKJytXhGJS2jdKQYP8JIDQqQTfRBJprEmW7du-9jRWwf8Xj31JzRKg4B6h8PbmDRXpko7Mc68MvhynF6RygeNJqF0vDSvhyq1WJysbTea4Jbb7aHvatwSwK73Z6AOKuHguj+AAQsMWAANJYAqcYJnuK4nmm5SgeBUEwbul5XmiMAcrQ7wbroABioxYlGiaYVhJi0M8erlMRpGuBRw4klecFMcmM4PGOLATlx07MKe86Ls2V5AuuyFgE6ETwWiVHUOQjDlHJClnsJMktsadbJJpCrkVhLY4fJeEiHsqTqSxK5sVeEiMEQgioNxinJECU7PDOgnniJK5ibABGfjuemUbQ8kyEpwUqUJF76Ua8r3vKunqdhuH4aZLjmfBFlohZJIkrQJi6OwKgKbO2iDPGugopeojwhArCjOg7AFgAJN4kTNVqjA6IwJKEkoYCEpKQA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_g_response.Rd b/man/tm_g_response.Rd index 4c34a0f6f..e5454501b 100644 --- a/man/tm_g_response.Rd +++ b/man/tm_g_response.Rd @@ -19,7 +19,8 @@ tm_g_response( ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"), ggplot2_args = teal.widgets::ggplot2_args(), pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -80,6 +81,12 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like \code{shiny::helpText()} 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_response}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -96,6 +103,18 @@ as frequency or density. For more examples, please see the vignette "Using response plot" via \code{vignette("using-response-plot", package = "teal.modules.general")}. } +\section{Decorating \code{tm_g_response}}{ + + +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{ # general data example data <- teal_data() @@ -184,13 +203,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6uoxwAI6CtNXsPqKkxNREjIoQlTCtLKJxur0E-RWmHbrsWroqugTsCoSs1Iuli1qiq7qLsFuLUiyLcrbl3ZVDfYyiwMBaALp3g1DiJuqkHezD-Tf3d12VAF8lACuko0KhBio8gszildABefwZXBjPhCEQDRFo4RiGHnXSkGCJCSJaqiVAkURwPH43TUKD0OB+RGLLBiCkQKm6AAK7VImzwY3xZI5XMRKUSYVIzA0iXJcHmQtpKWg8AR2zAXyuqyV+KpIg06v1CtIctQCpptPO9MZzI1AGUmSbdFoWLQGSJEDqzlbKgR8kRaAQxOrXYx3fQRIl-YHg6JihkbostQKHqVFUsVngNQdGEc5Cifb7jRo4Px1YsCMtvb7zjBhJpInpEQAxACCABl7c5C7XKiZaKEy+r213XEX8f9aQXdbpQuqJVKZab5YqJ+cVbBmxqUzXi07DYiSyvzWu+3SGUyK2BHQbSC63R64F7Bev8TGgyHEWGI1GP3GEyCJNNUuVM7nTBYwA2PYUBgfNez7Y9hxZKCBQQ2t62oRsRBHTtu3Q30ByHctWzw8daynSclSnLouloExJhUchl20aljjKMZREKCBWDbdB2HBAASepSiEqlGB0TpgSUMAATuIA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXQGEAIgEkAZS9dfihSKF04AA9YVBElUPCDYy5qAH1EqBsEsIijXQB3WlIACxV2TNxdECVdXUY4AEdBWgb2CDFSYmoiRkUIOoBBHwCAGWT64bGlAF9+gCsiFTSAazhWUQrc23z+OBMoYVI0gn5aUQI0xeW1jeBoeE3MuQBdN2h0CZVi9lqQ3N0AF5-uFcH8+EIRKIgboIcIxL8BnVdKQYGkJGkGqJUCRRHBEcjkdQoPQ4NQYQowFgxDiIHjdAAFHqkUSUsFIwlY2n04GZNLRUjMDRpbFwAgEwnIzIPPTAylTUZsv6S3R4kQaGFqsXHUXi5Uq3TE0nkuVgAJk7W6LQsWgkkSIJUcg0EEpLAhiGHWxi2+giE6u2jup65YDAeUjRVgF4vKp6sAAIQAslgANJYABMbN0lK8AHlHAA5BwATUpcjk7INyK1Gjg-ApCeTaczeH1KpgR1ocVlugAYoNRgFnJWq6ZaFE6zD+4PXE7Cf0VRW27oojC+QKhTrUGKJSrpbAe+Hpq259WLRrgTWtzvl4SjWSG+b1aQrTa7XAHSfR7oXW6PcCvR9P1f0DBFMlDI9I2jWNfjNZwAA0s0pLBBi8VwwHLEcqyvSdTRQtDHW-DtqE0bspwHIcsINExx1wvsKNnKsF0lZi6mY-p+loExdHYFRyE3bR8XLao-lEMoIFYQZ0HYNBUAAEhaKpZLkvFGB0PpZiUMAZheIA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_g_scatterplot.Rd b/man/tm_g_scatterplot.Rd index 5c1c306f7..4f90024f2 100644 --- a/man/tm_g_scatterplot.Rd +++ b/man/tm_g_scatterplot.Rd @@ -23,7 +23,8 @@ tm_g_scatterplot( pre_output = NULL, post_output = NULL, table_dec = 4, - ggplot2_args = teal.widgets::ggplot2_args() + ggplot2_args = teal.widgets::ggplot2_args(), + decorators = NULL ) } \arguments{ @@ -93,6 +94,12 @@ with settings for the module plot. The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. For more details see the vignette: \code{vignette("custom-ggplot2-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_g_scatterplot}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -107,6 +114,18 @@ trend line additions, and dynamic adjustments of point opacity and size through For more examples, please see the vignette "Using scatterplot" via \code{vignette("using-scatterplot", package = "teal.modules.general")}. } +\section{Decorating \code{tm_g_scatterplot}}{ + + +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{ \dontshow{if (require("ggpmisc", quietly = TRUE) && require("ggExtra", quietly = TRUE) && require("colourpicker", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # general data example @@ -280,13 +299,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsBISqDC0ogT+uLpetHCk1Ky6ALz2Ts62AGTpuu7Rvv6BzgAepMwRUd6x8UkpLhlZOd55hETURIKMqLQEANYyZdGVCckOtUoAxLpSEGrUuvxQpFC6cIWwqCJK84sGxlzUAPpbUDabC0tGugDutKQAFirsR5EgSrrZno1w7NOipMStjEUEDeAGEAPIAJh2unBEKUAF8gUo0KhoSobn5gXMztUnq9dHwhCJRNVCcIxJi3m9SDB9hJ9mEFuQOq1SJSqW9qFB6HBZsl-ABlAhMmTrIikGG3IhdMQRfEcwq4s77FYldSkBmoOAEdkct5HaDwar+WFyrF63SiXnaiXJK0iDSa7W6i26Lk8vm6QXWjS6LQsWjckSIM2uqkEKUyknJf2MQP0ET7CPSggUo7AYAmyH+AC6OciOv8xAsZX8glQi16-jkclw8td9ptcH4xuaJbw9YtMGEmnWemSADEAIIAGQFzjr5tdJlohWb1WHY9cU45QIttc7uiG2MWKuKzEdoi1hZXVINsH7XrApo7p7ejd9dp9GqPzs3HPdvNbAuffoDQbgENbzDN5kyjapY3jRMwNTURHjODMszhMA8wLPw23CPAr3LSs4GrDc7ypB9yBbfkwBwqAq2AkDu2oXsRAXUdx0nEDTFnedByY5cwzXPUCItf4iEYfZ6G3I49zVQ9jxdDlzyNMibxYhtfyfB0X2k98qU-T1vTUv84wAoClLDGCxAg-8EzgJNI1gmTXXTTNr2zFD800jlCzAAAFLkyFLMA7FYLU-LsdwFngXysKLEhMMiMsK0ovCwF4njjOUtSON0AA5RwRxHVKux7Wg+0Ypd8r1Gc51I3RF3HTTkqpfi9VEWgAC8rNEpVd1VA91LfQi5MvJDQzSm1qmIp0T1Y7Tv1-SDDOGkybLMmMLOgpa4IcoaXLQqL21i8j4qomsyo5YiMri3CFtdWj6MvGqJzctjKpK2rCPqt5Go5RgiEufYTHUWJOqgCSeomuz9TOQ1Bqc5CTstFT4bUsHHumsifz0ubLKMx7TOjfSoKs3H4MWRCYdzfNdA87yoAi-aAqCyL-NCmkKFIfC4fvZ8Muy3KOYJQris40rHoqjL7rqzdPvDFo-oB20d2B7r1WR-rIYvVtFM04ixufFWpu5L80dm1bAKugT1vMgzLOslM0wQxyb1Qyn0Op2mr3pxK6eZ8K2aSqWLTOqqebyx6bqKhiheYkX2Kq8W3sl+teKBIFaBMXR2BUZl1W0L4a10F4sVEe4IFYId0HYFEABJvEiKurUYHRAQRJQwHhHMgA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsBISqDC0ogT+uLpetHCk1Ky6ALz2Ts62AGTpuu7Rvv6BzgAepMwRUd6x8UkpLhlZOd55hETURIKMqLQEANYyZdGVCckOtUoAxLoAwgAiAJIAypO6-FCkULpwhbCoIkorawbGXNQA+vtQNnur60a6AO60pAAWKuznkSBKutmejXDsEDEpGIrUYigg3wAgtN5gAZQ7ZaFwpQAX3BACsiCoTr1WKI3tdbLd+HATFBhKQTgR+KECCdMdjcaJgNB4PjznIALpKJRoVAIlSPPwQ5bXarvL66PhCESiarS4RiYXfb6kGAnCQnMKrcgdVqkZUq77UKD0ODUar+eYEHUyHZEUhTJ5YghiCKSo2FcXXE6bErqSmiVBwAiGo3fc6svTJfxI2HukXh3Sic0hx3JFMiDRa4Ohj1J3Qms0WmNgeapjS6LQsWimkSIBMFlUEZ1dMTVauMWv0ERU1uu9nXYDAWMw+NgTmcyJ5sCQgDirjwun8ACEALJYADSWAAjGVVxvtwAmfxyOS4fNJzNpuD8S2zheNptSim0HbR3QAMUhsPmzgviYFiYtCFLe1Tfr+riAUa4JJuel66EMoprL6xTMNmQYhmG4aRrAH6jsieAId816VhmFaBrm2FJkW5r3uWWaOp23b1k+TYti67bJMxdZwH2nGDmsw4EeOk7Tn4D6LpEB5bru+5gOusknmAZ4Ac+yYUWBpaKdue5EdB4YwK+77gT+f5qc+wGgXeyQQX+xG6LB4bwQZIJEIwJz0Eh5yof6GFUQ5uHwPecZseGpHphpjE5lhDnGqadGlgxaZVjWvENvp6kcW2crcWlPZ8dlA7UQW5zCbOY7+GJcXNhJ85ScuCmHnJS4yce8lYJCkwNf4WDOHOswAPIAHJ6U5TYuepEVabow2OLCsIWU2RnUJoJm2WZ-41VZM12VBE0IZN4W0AAXnxXneihfroZRsUGRG1xRiFlWZQWEXVBFMV5vdKq0SWjXJZWPEFRlS0FkVXGpV2vH8TlBJCSOFWEWJugzvV8k6S1qk1dNNmNejr3LcZIimZBYNJjteN7Q540qkdRqMEQdwnGSrqRT510Bl9JUPWsT2lqFhPhRRH0UdzNV-fRIvA6xQtJhDuVQyxhX9kqZWI4LKMzpjynSWAnXdR1-VDaNp7029ml43NC3k4ZxMfntttGpTpP2T9tPfOb3wgiz6ixJdUC+Td4s-UF+FI+OTtRSl5HRZh33qZLSXS-lstR97quKzLKsCfDUDlZrU6oxJOsdV1PX68bI1jV7wuMTN1uLTVK1rSTG1k9tIG7ZtNOHfmTnguCtAmLo7AqLqAbaP8Z66J8IqiC8ECsJC6DsHyAAk3iRBvKaMDoYKokoYAopyQA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_g_scatterplotmatrix.Rd b/man/tm_g_scatterplotmatrix.Rd index ec2645a59..a0af16a82 100644 --- a/man/tm_g_scatterplotmatrix.Rd +++ b/man/tm_g_scatterplotmatrix.Rd @@ -10,7 +10,8 @@ tm_g_scatterplotmatrix( plot_height = c(600, 200, 2000), plot_width = NULL, pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -34,6 +35,12 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like \code{shiny::helpText()} 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_scatterplotmatrix}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -47,6 +54,18 @@ providing the overview of correlations and distributions across selected data. For more examples, please see the vignette "Using scatterplot matrix" via \code{vignette("using-scatterplot-matrix", package = "teal.modules.general")}. } +\section{Decorating \code{tm_g_scatterplotmatrix}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{plot} (\code{trellis} - output of \code{lattice::splom}) +} + +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{ \dontshow{if (require("lattice", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # general data example @@ -188,13 +207,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CmlCkmgRw-ri6XrRwpNSsugC89k7OihAAxLpSEGrUuvyBULpwAB6wqCJK+aSFRrpc1AD6VVA2lQUGxgDutKQAFirszeEgSrq6xOakjFGiHXkFGCbM8H4QY2O0-AnjfmAAIq54uv4AYlhhx2AAknYX-s4AyndgAAq3R-4A4ucfYAByABlngAhQ7hfwAxzPACC7zkuFG6wkRB0jAg8DI2xM6lIREYq3W6wI7AATOEyboKQBGcm03Q0+nhBkk+GIwnUKD0ODUWaJYn+ACyJBYBF6rGeWDgqEE9DoBH8qUJrLW6w5EAkgigUga2JgtFiWJxeIJhJ2DIAzOFLbprdbqUyrUzlabdByuTztvywJ8ZDAoMp5b8ABLckQBiVEP0WUJgRXrZ3rVBEaUczQkT3sAAc1oAbAB2cI5gAM4QALAX6SX6QyqRWqQyixgc+EAJwJsYsOCFPnsc0AVgrfb7FqLDL7Rb7rep5oppZH5Kb4Wz7cy-FQGfNGFLC4rJIwNa34Ub1sbFMbFcbk90jYbW5X-Dg9FIGb3zIwdsPlMXX4-25-C7-PdfzjONRG4MQ5maRZljgE0Ni2RIqUQccERVMYJjINgGk2bYwJgcpYLZIldgOZ4zmeG5nkeZ43meb5nkBEEwUuSEYThVCXVEWgAC89ESFCiLGdxynUPikhcIiV1YLtGFwvFSHYPCCNJUci0QEkiw08IUN0YSORCbYHBcOQVx0CBBDEpSRHYL1RD9ahqGeeB+FoQQYGeDlGCkZ4SDobIFW0qs9NEwzkhXAh-RCBy4AQ3QrNg4kjOccITmhAEHhSQLwmCgzEiSlcvH9TRSDiRI0TxGB2B0qkiyrDTwqIURSF5XSIAqqqq0zOqixXVBGCIEwem2crGEqnStMrEClAAX1SAArIgVAaABrOBWFEQYClsWoFqW1b1pNXaIBWtbdgwqYZmec7pjEZ5NgCxEjpOjh-DAkRRGeN7bt+e7Yw43Qnv2s6iEmG6Pt+L7wfCL1fu2fxrtYbD+AVVJUiUNB11qFQehNZptiGRE+CEd7tiJ4QxDguoYAaCQGlECKghkcoiFIP0LuKSmxjdbk4bAB4GfIRhmefNnpmKMJBN0LQWFoTkScSOgms59ZmgaEophxOnUDgfk0JdeZqmgeBeeuy68ElwlRG5HXn0SK2RA0LWdeVl1udyRJ-Aea2NClmW5bERAJb1-Xxl6RaQha6Xpn9hpRXDinmmAYB4ZBzCzYAXXTlcQ-tm2YozfxOygZ4JDXZ4HyfB7g-1mBhE0AjQpcf6Q7GPEH3cWKkublvBuKfPElS9LXGrpULd0bOVYKNXig1x3RG13WW4N-1YDE17wKhsexkG6hBaxfVBadxel9dTkeY9vnvefKPZdlOBA-NkfTSjlqU9BxHfu7kO49oCPtml6gFlY5h1-gnAoSd17vX8JncEhBU5TA-sjP6W91i5w0P3HY-hSK-HIr8SivxqK-For8eivxGK-FBM8VivxYRVxProWuu9aANzyskFBE9LZX1wlfI+LtTRu15l7B218-Z31EA-L++sf5-0SDfGO0iwHVAgWASG0D07Q12IVMgPRxS-GIE1KGlw+oDR6CjSRnEr4YK9Fo4qujYH6Oas8Yxg1SB0JPow+uIhG7JRQa3Rg7cMFd18aYWgfdYqDwyuwsecZR56ymhAVItATC6HYCoQWOJtCwRMroEYKpRD9AgKwaE6B2AYwACTeHCOUq2jBUSpGmkoMA0105AA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CmlCkmgRw-ri6XrRwpNSsugC89k7OihAAxLoAwgAiAJIAypm6-IFQunAAHrCoIkolpGVGulzUAPr1UDZ1pQbGAO60pAAWKuwd4SBKuroAgtn5ADK9uoxzi1Oz2Vj5y6tb+UoAvqkAVkQqrQDWcKyiY6W2TfxwJlDCpK0E-LSiBK1nF2ut2A0Hgdw6cgAukolGhUMsVIM-BBph0EsVSrgNnwhCJROiccIxMjptNSDBWhJWr9AuRGDUiOTAoxaBUSaTptQoPQ4NR0f58gRaTIGaRdDBmaywhsOVoWLRuXj0XRRKR2RzUaVWpVSMwNNTUHACOqNZqGqC9Il-GsFtKUabSaJeUaxYknSJ9aJDcaZQ7OdzefywPlnRpdHKWYqxIg7X6OQQhucQvjEhGFfQRJ9E7Rk-cGsBgNb5rawJDIXIsfa47p3S64Px0T6wDMAOKuPC6fxYGaZdvhAXOAAa-grvr9MHetBqlqSLkr1emREYz3cDcSDjnY4dJlZ9fRADEZgt8q4qw7Un7R2eOR1tRVdeoPl6jSbTR0LUG5ttY3Gd9Q6eif50gaL5bqaXI8nyVrBqGYoUPwqDnGQogxngYEahGKa6E2AAKMzdgAsjkYSds2ABqBS5HYI7zguCZJmI6JytQghwFmDHgqUBZFt+paQuEuH4TMRHZCR1oUfkVE0dhfhgHhhFieRlHUWAchXguNawXu0G5AAcmRzh2LoxjOLp2S6AA8vuuh6dkjiZHYuQWbpP7VhO-5TiI6Ibqe1bqXGtZhm6sEgT614OhBgbQSGHpimmUYoa5cb0TmjGpvKUbsalnH5oWzb7P4Zb+dWgXkGuMnWm2ikzGRR7VdkACaNHoRy7maNO3nJLR1ZLiu2mzs43W-ru5WHsevlxhe55blN0xTakqS0CYujsCodKPtocA2LYkz2qIIwQKwMzoOwcIACTeOE51OowOiMKkhxKGAhyQkAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_missing_data.Rd b/man/tm_missing_data.Rd index a758b5a85..c6cd75b96 100644 --- a/man/tm_missing_data.Rd +++ b/man/tm_missing_data.Rd @@ -14,7 +14,8 @@ tm_missing_data( list(caption = NULL)), `Combinations Main` = teal.widgets::ggplot2_args(labs = list(title = NULL))), pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -33,9 +34,7 @@ ignored.} \item{ggtheme}{(\code{character}) optional, specifies the default \code{ggplot2} theme for plots. Defaults to \code{classic}.} -\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} -with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. -The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. +\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. List names should match the following: \code{c("default", "Summary Obs", "Summary Patients", "Combinations Main", "Combinations Hist", "By Subject")}. @@ -47,6 +46,12 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like \code{shiny::helpText()} 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_missing_data}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -57,6 +62,38 @@ gain insights into the completeness of their data. It is useful for clinical data analysis within the context of \code{CDISC} standards and adaptable for general data analysis purposes. } +\section{Decorating \code{tm_missing_data}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{summary_plot} (\code{grob} created with \code{\link[ggplot2:ggplotGrob]{ggplot2::ggplotGrob()}}) +\item \code{combination_plot} (\code{grob} created with \code{\link[ggplot2:ggplotGrob]{ggplot2::ggplotGrob()}}) +\item \code{by_subject_plot} (\code{ggplot2}) +\item \code{table} (\code{\link[DT:datatable]{DT::datatable()}}) +} + +Decorators can be applied to all outputs or only to specific objects using a +named list of \code{teal_transform_module} objects. +The \code{"default"} name is reserved for decorators that are applied to all outputs. +See code snippet below: + +\if{html}{\out{
}}\preformatted{tm_missing_data( + ..., # arguments for module + decorators = list( + default = list(teal_transform_module(...)), # applied to all outputs + summary_plot = list(teal_transform_module(...)), # applied only to `summary_plot` output + combination_plot = list(teal_transform_module(...)) # applied only to `combination_plot` output + by_subject_plot = list(teal_transform_module(...)) # applied only to `by_subject_plot` output + table = list(teal_transform_module(...)) # applied only to `table` output + ) +) +}\if{html}{\out{
}} + +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{ \dontshow{if (require("gridExtra", quietly = TRUE) && require("rlang", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # general example data @@ -113,13 +150,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsBKMtPzOAB6kzP64ul60cKTUrLoAvPZOzrYAZJm67rG+-ozUUBASUTHe8YkpaS6KEADEulIQatS6cKGwqCK6-FCkUEr9gwbGXNQA+iNQNsMDUGO6AO60pAAWKuwz0SBKurme3r6toqTE1ESM9fu6UPz8k9CiS2YWmtahtnsQBwehwFE3RE7FEnkm3BIEnYX2iJkuV3YIlKGxhtgAVLlzLQTOwAIzRDAABgArIS8QB2OTUgC6SwAcgBBW7-W4AXyUtx8tBeRl03NEtxg5xYvOMwoIos5v35QVEwDpfOK6ES7AF0Xuj2e9QOEtFCqWyp6HD1jFEGoeTygoh1ulN8uA-gIrGo-hpiuM1owJnUpER9uAjsILrdNNtAaDUhYoaWXp9Gn9IrNgf8UcYofqbJu0HQSxUaz8MpmNR2QoEwjENT4QhEokLf10pBgkxgPNEKgk0wWcxl9XqON0atUzEsOhs31uok2EFYjPQ7DQqAAJN4Negl2DGDprkoORAwGyaUA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsBKMtPzOAB6kzP64ul60cKTUrLoAvPZOzrYAZJm67rG+-ozUUBASUTHe8YkpaS6KEADEugDCACIAkgDKzbpwobCoIrr8UKRQSiNjBsZc1AD6k1A2E6NQ07oA7rSkABYq7IvRIEq6uZ7evhBipMTURIz1pwCCrZ0AMuuML+8nui9YnU+-06SgAvvUAFZEFRzADWcFYogOq1sRmGcBMUGEpDmBH4tFEBDmUJh8MRwGg8CRizkAF0lEo0Kh1iptn4IKdFjVDr8+EIRKIanzhGJ2adTqQYHMYATRCoJAtVssObp6vVaCZdOwVORmJYdDZbMcVaI9hBWE90OwmQASbzRW2iGQ6B5gpRgUG0oA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_outliers.Rd b/man/tm_outliers.Rd index ff738de8d..106ba0ec4 100644 --- a/man/tm_outliers.Rd +++ b/man/tm_outliers.Rd @@ -13,7 +13,8 @@ tm_outliers( plot_height = c(600, 200, 2000), plot_width = NULL, pre_output = NULL, - post_output = NULL + post_output = NULL, + decorators = NULL ) } \arguments{ @@ -28,11 +29,9 @@ specifies the categorical variable(s) to split the selected outlier variables on \item{ggtheme}{(\code{character}) optional, \code{ggplot2} theme to be used by default. Defaults to \code{"gray"}.} -\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} -with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. -The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. +\item{ggplot2_args}{(\code{ggplot2_args}) optional, object created by \code{\link[teal.widgets:ggplot2_args]{teal.widgets::ggplot2_args()}} with settings for all the plots or named list of \code{ggplot2_args} objects for plot-specific settings. The argument is merged with options variable \code{teal.ggplot2_args} and default module setup. -List names should match the following: \code{c("default", "Boxplot","Density Plot","Cumulative Distribution Plot")}. +List names should match the following: \code{c("default", "Boxplot", "Density Plot", "Cumulative Distribution Plot")}. For more details see the vignette: \code{vignette("custom-ggplot2-arguments", package = "teal.widgets")}.} @@ -48,6 +47,12 @@ with text placed before the output to put the output into context. For example a \item{post_output}{(\code{shiny.tag}) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like \code{shiny::helpText()} 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_outliers}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -57,7 +62,40 @@ Module to analyze and identify outliers using different methods such as IQR, Z-score, and Percentiles, and offers visualizations including box plots, density plots, and cumulative distribution plots to help interpret the outliers. } +\section{Decorating \code{tm_outliers}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{box_plot} (\code{ggplot2}) +\item \code{density_plot} (\code{ggplot2}) +\item \code{cumulative_plot} (\code{ggplot2}) +\item \code{table} (\code{\link[DT:datatable]{DT::datatable()}}) +} + +Decorators can be applied to all outputs or only to specific objects using a +named list of \code{teal_transform_module} objects. +The \code{"default"} name is reserved for decorators that are applied to all outputs. +See code snippet below: + +\if{html}{\out{
}}\preformatted{tm_outliers( + ..., # arguments for module + decorators = list( + default = list(teal_transform_module(...)), # applied to all outputs + box_plot = list(teal_transform_module(...)), # applied only to `box_plot` output + density_plot = list(teal_transform_module(...)) # applied only to `density_plot` output + cumulative_plot = list(teal_transform_module(...)) # applied only to `cumulative_plot` output + table = list(teal_transform_module(...)) # applied only to `table` output + ) +) +}\if{html}{\out{
}} + +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{ + # general data example data <- teal_data() data <- within(data, { @@ -102,6 +140,7 @@ if (interactive()) { shinyApp(app$ui, app$server) } + # CDISC data example data <- teal_data() data <- within(data, { @@ -112,6 +151,8 @@ join_keys(data) <- default_cdisc_join_keys[names(data)] fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl)) + + app <- init( data = data, modules = modules( @@ -150,14 +191,14 @@ if (interactive()) { \section{Examples in Shinylive}{ \describe{ \item{example-1}{ - \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6ugDCAPIATHHV9RVNdcDACmCojLQwLKyJANZwrJ0AumONonAAjokiEOwQjETZ7LV1cooQAL7bAFZEKkMjosUZtlmHx8OsZ9cQJxydG52lL814up3dvf1PnS2bggWhYokaBHyRwIYkS0xEGjg-HYoJ6UHoIkSkOhYnOQXaHzq4zGpQI7E6AAVqFAyG9vmA7KxUHA6Z07Iw4IF4LSwFttko0KhGio8uSIJUUroALz+DK4Fp8IQicEyxXCXEtSqkGCJIiCUh0GRnTWVXR6g20GSJVHS3R0USkMWm52yoKJMKkZgaOHMskml2ummwPQywlvf0u+FwDS2qPe0S+p0Bl3U+hwPyhsAAZXT0dIulRtHRIkQ4fFyed2NoMJVBZYRYxcCxUOruJSBLArzAE1J5MIJAIrLAglQQWGgLk8vLFcqcfI-FtnRHY5ZeAjAZgwk0kRDugAYgBBAAyWecU5nppMtFCSNth5Prmnye2FZfLsnEYIgTgEiIPS-SQ2jK9qOuugbuqEnrqKQPrRkmFYpNA8CLp2nznjOV7UOQjC2ph2GwX6T4VqitYkehF5VjWtqgtQghNpRbYZB2XY9nWjCiAAJHOSIfkRybcQuMo0XRzY4mc7YdKhRLdiSbGcQJvEXpUm5YbQO62g4LhgZUb4Brppr6W+2zbLQJi6OwKjYdB2hwDYtjlOWoiFBArAHug7CChxgi0KUnnTIwOiMNsOxKGAOxjEAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokrcQAxLqkQ11XfxQpFC6cAAesKgiSoHBBsZc1AD6sVA2MUEhRroA7rSkABYq7Km4uiBKuroAwgDyAEzxNQ2VzfXAwApgqIy0MCysSQDWcKxdALrjTaJwAI5JIhDsEIxEOex19XKKEAC+OwBWRCrDo6IlmbbZRycjrOc3EKccXZtdZa8teLpdPX0Dzy623cWhYoiaBAKxwIYiSMxEGjg-HYoN6UHoIiSkOhYguwQ6n3qE3GZQI7C6AAVqFAyO8fmA7KxUHA6V07Iw4EF4LSwNsdko0Kgmip8uSIFVUroALwBTK4Vp8IQicEyxXCXGtKqkGBJIiCUh0GTnTVVXR6g20GRJVHS3R0USkMWm52y4JJcKkZgaOHMskml2ummwPQywnvf0u+FwDS2qPe0S+p0Bl3U+hwfyhsAAZXT0dIulRtHRIkQ4fFyed2NoMJVBZYRYxcCxUOruNSBLAbzAk1J5MIJAIrLAglQwRGQLk8vLFaqcfI-FtXRHY5ZeAjAZgwk0URDugAYgBBAAyWecU5nppMtDCSNth5PrmnyZ2FZfLsnEYIQTgEiIvS-yQ2jK9qOuugbumEnrqKQPrRkmFapNA8CLp2XznjOV7UOQjC2ph2GwX6T4VqitYkehF5VjWtqgtQghNpRbaZB2XY9nWjCiAAJHOSIfkRybcQuMo0XRzY4uc7adKhRLdiSbGcQJvEXlUm5YbQO62g4LhgVUb4Brppr6W+Ow7LQJi6OwKjYdB2hwDYtgVOWohFBArAHug7CChxgi0GUnkzIwOiMDsuxKGAuzjEAA}{Open in Shinylive} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ - \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXQGEAIgEkAZS9dfihSKF04AA9YVBElUPCDYy5qAH1EqBsEsIijXQB3WlIACxV2TNxdECVdXQBBHwCAGWTdRkaWpQBfRQgAKyIVNIBrOFZRCtzbfP44EyhhUjSCflpRAjTB4bGJ4Gh4Scy5AF03CAWNNK0WUTSoflFqNoOxdgAxWmpyRnZ1hxcVVEaDiHEywGACjAnWaUJOJyq6wwl1IREYcgxShujFEbQIJSGBDEaVEcBEGjg-HY2NoUHoIhWBNoRKOuQhUJhcIRpnUy2xdweT0xECUILaKmK7FqIVyugAvDLwrhpXwhCJcQrVcI3tK6qQYGkiIJSHQZJNdXVdEaTbQZNcWPLdHRRKQpRBLR7FVA0tFSMwrqJUHACG7PZ7Mq9HRymrC8Baw6TyaRHYng8tA8HQ2HPdQ6WSo2AAmS07oaXSRIgocr3dmPfjCWJHWX6XBGQ3WeF2dCY1yqiGOQBxVx4XRQgBCAFksABpLAARihGOrtY9qYp-AL9SHVfj2ZgS1ocT0Cve9WaAWcy5XdRMtCilMdp-Prhrtb6b93civdbCcAkaOZbh7UYR1nVdXc6kyH0oj9XkSSDftX2zCNYGPUduy6OMkLDW9vhkR1cJ+eDMwgz1+SbW5vxXetmUbBUbmoQRWxolkpk7SEMNjeEqn5AASNdyH4L9SNXYt1woxjmKZVjwQ4zkwG40tbn4sTBOE7C9wPI9HQBF9r3fbMDI9IzdAMvo+loExdD+VR-U0HQbFsGoa1EMoIFYep0HYEFeMEWgqh80lGB0dEeiUMBuhOIA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokrcQAxLoDCAEQCSAMreuvxQpFC6cAAesKgiSmERBsZc1AD6SVA2ieGRRroA7rSkABYq7Fm4uiBKuroAgr6BADIpuoxNrUoAvooQAFZEKukA1nCsopV5tgX8cCZQwqTpBPy0ogTpQyPjk8DQ8FNZcgC67osa6VosoulQ-KLU7Ydi7ABitNTkjOwbDi5qqI0PEOFlgMAFGAui0oadTtUNhhLqQiIw5BilDdGKJ2gRSsMCGJ0qI4CINHB+OxsbQoPQRKsCbQicc8hCoTC4QjTOoVti7g8npiIO4lCD2ioSuw6qE8roALyyiK4GV8IQiXGKtXCN4y+qkGDpIiCUh0GRTPX1XTG020GTXFgK3R0USkaUQK2epVQdIxUjMK6iVBwAjur1erKvJ0c5qwvCW8Ok8mkJ1JkMrIMhsPhr3UOlk6NgQJk9O6Gl0kSIKEqj05z34wliJ3l+lwRmN1kRdnQ2Nc6qhjkAcVceF0UIAQgBZLAAaSwAEYoRia3XPWmKfxCw1h9WEzmYMtaPE9Ir3g0WoFnCvV-UTLRopSnWeL65a3X+u+93Jr-XwnAJGizLcA6jBOi6bp7vUWS+tE-q8iSwYDm+OaRrAJ5jj23Txsh4Z3t8MhOnhPwIVmkFevyza3D+q4NsyTaKjc1CCG2tEstMXaQphcbwtU-IACTruQ-DfmRa4lhulFMSxTJseCnGcmAPFlrcAniUJIk4fuh7Hk6AKvjeH45oZnrGbohn9P0tAmLofyqAGmg6DYti1LWojlBArANOg7Agnxgi0NUvmkowOjor0ShgD0pxAA}{Open in Shinylive} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_t_crosstable.Rd b/man/tm_t_crosstable.Rd index a9a1354cd..dc3ab1578 100644 --- a/man/tm_t_crosstable.Rd +++ b/man/tm_t_crosstable.Rd @@ -12,7 +12,8 @@ tm_t_crosstable( show_total = 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{ @@ -49,6 +50,12 @@ with settings for the module table. The argument is merged with options variable \code{teal.basic_table_args} and default module setup. 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_crosstable}" below for more details.} } \value{ Object of class \code{teal_module} to be used in \code{teal} applications. @@ -61,6 +68,18 @@ options for showing percentages and sub-totals. For more examples, please see the vignette "Using cross table" via \code{vignette("using-cross-table", package = "teal.modules.general")}. } +\section{Decorating \code{tm_t_crosstable}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{table} (\code{ElementaryTable} - output of \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{ \dontshow{if (require("rtables", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # general data example @@ -159,13 +178,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsIykUPQiov64ul60cKTUrLoAvPZOzooQAMS6UhBq1Lr8UEG6cAAesKgiSgVFRrpc1AD61VA2VYVQBsYA7rSkABYq7M0RIEq6ujCkBCyinRNTM2OmRIy67Fq6KroEfoSs1OG6-lpheEcoMIf+Uiz+crajEOPjk9OMosDAWgC633NQ4hM6lIK3Yrxmnx+3zS4wAvktwe9Pv5UIxaDAWKwGgBrOCsfy-OaiTwNEQQdgQRhELpghbve5KWFpABWRBUOLxoiG7VstVZ7NxrC5-IgHI4-kRpwiErpUvOqPRmLFdzSSjQqDmKl6fie+XaiT1QVwCIEwjEBr4QlCOuedRgDVIDQIVNEoiCITgNttumowTgeSS-gAwi7ZnZgpU8EtbSUDc0GqVSMwNA1RKg4Dto97mtB4AaZW8pVnbcSRBoDaWM460xmvd7nr76P782AAMr+qu6LQsWgRuCIcLF70EPpsgjmpLdtF9p2j2jjrnNZFgSUE74RTN7A5nY5y-ywK5gG6MFXG3X18aVjRwfgGzcEfaH493M8X54wYSaCp6JIOFyvt9dBWfgZBvA0-2cAC3xMWgSjApIADEAEEABlW1cc9vRhLCoOeeIknjRNk2rdNM0w20c1gH9zlXKNyOeK9SArDsUxrMjAJ9P0A3OdsyyYqdew9Ac6I4kcxwnLsexnMT5zEbkgmXWjfg3XYH23aUwBOQ8Dx3I84FuMB7lw+tGPg84tJEwCP2oL8RANZC0MgodbRguDb0Q1D0Oc3RsNtXyfKWNI0loEw1hUchiO0T17l0R5LwGCBWCQ9B2HVAASbwInS4lGB0Rg0nhCAwFhb4gA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsIykUPQiov64ul60cKTUrLoAvPZOzooQAMS6AMIAIgCSAMpZuvxQQbpwAB6wqCJKpeVGulzUAPoNUDb1ZVAGxgDutKQAFirsHREgSrq6AII5BQAyfbqM80tKAL5pAFZEKq0A1nCsouM9tk38cCZQwqStBPy0ogStewfHp8DQ8GcdcgAukolGhUCsVEM-BAZh1EiUerhpro+EJQvDUcIxNCZjNSDBWg8CIwiKJREEQnAcbiZtRgnBqPD-FkSWT7ME6nhkTTKvCOq0qqRmBpWqJUHACNSabCer89El-OtFuFudLRAyJaR4eqRCKxRKpdLafTGQqwAUNRpdFoWLQOXBECqYUbcQRhvsCGJ4TbGHbKY93bRPf8esBgIqFsqwIDARFRIJ6OqtUkzBZNNYAbops6XbjaPxeU0AIQ29Bxc5BCIqYYyIaiCLUIgSIPcdgARjkEUl-hyZTg4V0-gACgB5Ap5AAaGgHw7Hk+opH8cjSuZp7lIgkYEHYcpDQTkwHzlUBK9X2yROZdOs1cH4TLAWRHjgAcg4AJpO1co+60Wry5IuBeX5EIw1zuHeSQOIBqpGiYtCVLe8IAGKzIsBSuJeNKnlhQHSvEST8oKwoPPq3aYbiHRyveSqflelrJro156uKZFfnS9AMveFq6lqPp+iIjpcuRNJuh6XpJHx9oBmJe5QGGEYbNGsaMQmSbwqmlgZhcWYwS6R4rKWtQcBMugvBgtwaCBDZNi21DtsuulGuum7bruFZQAeR4no5uLnj5MxMeQEGDuazgTrRuYwD+f7Iah6G4bmcEIcFKFoRhubYbimWnmkaS0CYujsCo5DEdoVLLjpzqiKMECsLM6DsGCAAk3gRM16qMDojBpJsShgJsgJAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/man/tm_variable_browser.Rd b/man/tm_variable_browser.Rd index b36911ed4..752c4c83d 100644 --- a/man/tm_variable_browser.Rd +++ b/man/tm_variable_browser.Rd @@ -104,13 +104,13 @@ if (interactive()) { \describe{ \item{example-1}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsKKoLADWdBBw-ri6XrRwpNSsugC89k7OtgBkGbruMb7+ABakMNQA7rT8UqSikdHecQnJqS6Z2bne+WAAVqIkdOS1MQ2JKQ4tSgDEulLhsrr8UKRQunAAHrCoIkoLSwbGXNQA+jtQNtuLy0a65aQFKuwnUSBKuro+tKJ7b4wfL7owpAILE+VwBQMYNQgr1KRHgUKuMLhfxMUFotzM1C+KLRBQxfwAwgB5ABMXyJxKUAF9FBAlGhUF8VGi-FD5hcmo8-nwhCJPilucIxCzXq9ioctCxaFB6CJDkwiKVRDJhSLXtRpXBMSl-AA1SXSkS6eWKmT+P6vGkWpQ02gmXTsFTkZiWHQ2WzPVmiO4QVgAQXQ7HpABJvFFg0rGDpGDTKUowJSALpAA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } \item{example-2}{ \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAoksZwAjoNrv2CsKKoLADWdBBw-ri6XrRwpNSsugC89k7OtgBkGbruMb7+ABakMNQA7rT8UqSikdHecQnJqS6Z2bne+WAAVqIkdOS1MQ2JKQ4tSgDEugDCACIAkgDK07pwAB6wqCK6-FCkUEp0TCwcgSFhcIoQu-sGxlzUAPo3UDZKL3e65aQFKuwvURASl0ugAgrNFgAZT6McFQ4Fg2Z2OzOGHg5GuCAAXyuXSIKkewTgrFE-z2UFsRh2cBMUGEpEeBH4tFEBEeeIJRJJwGg8FJLzkAF0lEo0KhPipaKQ-BAQR8UgCEXwhCJRE1lcIxDKQSDio8tCxaFB6CJHkwiKVRDJtTqQdRjXBqE1-AA1Q3G7bmy0yfwIkFXf1KK60Ey6dgqcjMSw6Gy2IGy3SiX4QVig9DsMUAEm8USzVsYOkYVyxSjAWMFQA}{Open in Shinylive} - \if{html}{\out{}} - \if{html}{\out{}} + \if{html}{\out{}} + \if{html}{\out{}} } } } diff --git a/tests/testthat/helper-functions.R b/tests/testthat/helper-functions.R index 1bc8546bb..4eb8908de 100644 --- a/tests/testthat/helper-functions.R +++ b/tests/testthat/helper-functions.R @@ -10,3 +10,17 @@ mock_data_extract_spec <- function(dataname = "MOCK_DATASET", ) ) } + +normalize_math_italic_text <- function(text) { + # Unicode range for mathematical italic (uppercase/lowercase) + math_italic <- intToUtf8(seq(0x1D434, 0x1D467)) # A-z + + # Standard letters + latin <- c(LETTERS, letters) + + # Replace math italic letters with standard ones + stringr::str_replace_all( + text, + setNames(latin, unlist(stringr::str_split(math_italic, ""))) + ) +} diff --git a/tests/testthat/test-shinytest2-tm_misssing_data.R b/tests/testthat/test-shinytest2-tm_misssing_data.R index af35629ab..debfcc1b1 100644 --- a/tests/testthat/test-shinytest2-tm_misssing_data.R +++ b/tests/testthat/test-shinytest2-tm_misssing_data.R @@ -109,7 +109,7 @@ test_that("e2e - tm_missing_data: Check default settings and visibility of the c ) ) - testthat::expect_equal(app_driver$get_active_module_input("iris-combination_cutoff"), 1L) + testthat::expect_equal(app_driver$get_active_module_input("iris-combination_cutoff"), 2L) app_driver$set_active_module_input("iris-combination_cutoff", 10L) app_driver$expect_no_validation_error() diff --git a/tests/testthat/test-shinytest2-tm_outliers.R b/tests/testthat/test-shinytest2-tm_outliers.R index b2af74f0f..a0b3a206e 100644 --- a/tests/testthat/test-shinytest2-tm_outliers.R +++ b/tests/testthat/test-shinytest2-tm_outliers.R @@ -198,7 +198,7 @@ testthat::test_that("e2e - tm_outliers: # IQR METHOD testthat::expect_identical(app_driver$get_active_module_input("method"), "IQR") testthat::expect_match( - app_driver$active_module_element_text("ui_outlier_help"), + normalize_math_italic_text(app_driver$active_module_element_text("ui_outlier_help")), "x