Skip to content

Commit 78bacc6

Browse files
authored
Merge branch '1187_decorate_output@main' into tm_scatterplot@1187_decorate_output@main
2 parents c5a15a2 + 09968a8 commit 78bacc6

16 files changed

+115
-67
lines changed

R/tm_g_scatterplotmatrix.R

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
#'
1919
#' @inherit shared_params return
2020
#'
21+
#' @section Decorating `tm_g_scatterplotmatrix`:
22+
#'
23+
#' This module generates the following objects, which can be modified in place using decorators:
24+
#' - `plot` (`trellis` - output of `lattice::splom`)
25+
#'
26+
#' For additional details and examples of decorators, refer to the vignette
27+
#' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation.
28+
#'
2129
#' @examplesShinylive
2230
#' library(teal.modules.general)
2331
#' interactive <- function() TRUE
@@ -168,7 +176,8 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix",
168176
plot_height = c(600, 200, 2000),
169177
plot_width = NULL,
170178
pre_output = NULL,
171-
post_output = NULL) {
179+
post_output = NULL,
180+
decorators = NULL) {
172181
message("Initializing tm_g_scatterplotmatrix")
173182

174183
# Requires Suggested packages
@@ -193,6 +202,7 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix",
193202

194203
checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
195204
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
205+
checkmate::assert_list(decorators, "teal_transform_module", null.ok = TRUE)
196206
# End of assertions
197207

198208
# Make UI args
@@ -203,7 +213,12 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix",
203213
server = srv_g_scatterplotmatrix,
204214
ui = ui_g_scatterplotmatrix,
205215
ui_args = args,
206-
server_args = list(variables = variables, plot_height = plot_height, plot_width = plot_width),
216+
server_args = list(
217+
variables = variables,
218+
plot_height = plot_height,
219+
plot_width = plot_width,
220+
decorators = decorators
221+
),
207222
datanames = teal.transform::get_extract_datanames(variables)
208223
)
209224
attr(ans, "teal_bookmarkable") <- TRUE
@@ -234,6 +249,7 @@ ui_g_scatterplotmatrix <- function(id, ...) {
234249
is_single_dataset = is_single_dataset_value
235250
),
236251
tags$hr(),
252+
ui_transform_teal_data(ns("decorator"), transformators = args$decorators),
237253
teal.widgets::panel_group(
238254
teal.widgets::panel_item(
239255
title = "Plot settings",
@@ -267,7 +283,14 @@ ui_g_scatterplotmatrix <- function(id, ...) {
267283
}
268284

269285
# Server function for the scatterplot matrix module
270-
srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variables, plot_height, plot_width) {
286+
srv_g_scatterplotmatrix <- function(id,
287+
data,
288+
reporter,
289+
filter_panel_api,
290+
variables,
291+
plot_height,
292+
plot_width,
293+
decorators) {
271294
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
272295
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
273296
checkmate::assert_class(data, "reactive")
@@ -364,7 +387,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
364387
qenv,
365388
substitute(
366389
expr = {
367-
g <- lattice::splom(
390+
plot <- lattice::splom(
368391
ANL,
369392
varnames = varnames_value,
370393
panel = function(x, y, ...) {
@@ -388,7 +411,6 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
388411
alpha = alpha_value,
389412
cex = cex_value
390413
)
391-
print(g)
392414
},
393415
env = list(
394416
varnames_value = varnames,
@@ -407,8 +429,13 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
407429
qenv,
408430
substitute(
409431
expr = {
410-
g <- lattice::splom(ANL, varnames = varnames_value, pch = 16, alpha = alpha_value, cex = cex_value)
411-
g
432+
plot <- lattice::splom(
433+
ANL,
434+
varnames = varnames_value,
435+
pch = 16,
436+
alpha = alpha_value,
437+
cex = cex_value
438+
)
412439
},
413440
env = list(varnames_value = varnames, alpha_value = alpha, cex_value = cex)
414441
)
@@ -417,7 +444,12 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
417444
qenv
418445
})
419446

420-
plot_r <- reactive(output_q()[["g"]])
447+
decorated_output_q_no_print <- srv_transform_teal_data(id = "decorator", data = output_q, transformators = decorators)
448+
decorated_output_q <- reactive(within(decorated_output_q_no_print(), print(plot)))
449+
plot_r <- reactive({
450+
req(output_q()) # Ensure original errors are displayed
451+
decorated_output_q()[["plot"]]
452+
})
421453

422454
# Insert the plot into a plot_with_settings module
423455
pws <- teal.widgets::plot_with_settings_srv(
@@ -451,7 +483,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
451483

452484
teal.widgets::verbatim_popup_srv(
453485
id = "rcode",
454-
verbatim_content = reactive(teal.code::get_code(output_q())),
486+
verbatim_content = reactive(teal.code::get_code(req(decorated_output_q()))),
455487
title = "Show R Code for Scatterplotmatrix"
456488
)
457489

@@ -470,7 +502,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
470502
card$append_text("Comment", "header3")
471503
card$append_text(comment)
472504
}
473-
card$append_src(teal.code::get_code(output_q()))
505+
card$append_src(teal.code::get_code(req(decorated_output_q())))
474506
card
475507
}
476508
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)

man/tm_a_pca.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tm_a_regression.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)