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_teal_transform_data(ns(" decorator" ), transformators = args $ decorators ),
237253 teal.widgets :: panel_group(
238254 teal.widgets :: panel_item(
239255 title = " Plot settings" ,
@@ -267,7 +283,8 @@ 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 <-
287+ function (id , data , reporter , filter_panel_api , variables , plot_height , plot_width , decorators ) {
271288 with_reporter <- ! missing(reporter ) && inherits(reporter , " Reporter" )
272289 with_filter <- ! missing(filter_panel_api ) && inherits(filter_panel_api , " FilterPanelAPI" )
273290 checkmate :: assert_class(data , " reactive" )
@@ -407,8 +424,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
407424 qenv ,
408425 substitute(
409426 expr = {
410- g <- lattice :: splom(ANL , varnames = varnames_value , pch = 16 , alpha = alpha_value , cex = cex_value )
411- g
427+ plot <- lattice :: splom(ANL , varnames = varnames_value , pch = 16 , alpha = alpha_value , cex = cex_value )
412428 },
413429 env = list (varnames_value = varnames , alpha_value = alpha , cex_value = cex )
414430 )
@@ -417,7 +433,12 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
417433 qenv
418434 })
419435
420- plot_r <- reactive(output_q()[[" g" ]])
436+ decorated_output_q <- srv_teal_transform_data(id = " decorator" , data = output_q , transformators = decorators )
437+ decorated_output_plot_q <- reactive(within(decorated_output_q(), print(plot )))
438+ plot_r <- reactive({
439+ req(output_q()) # Ensure original errors are displayed
440+ decorated_output_plot_q()[[" plot" ]]
441+ })
421442
422443 # Insert the plot into a plot_with_settings module
423444 pws <- teal.widgets :: plot_with_settings_srv(
@@ -451,7 +472,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
451472
452473 teal.widgets :: verbatim_popup_srv(
453474 id = " rcode" ,
454- verbatim_content = reactive(teal.code :: get_code(output_q( ))),
475+ verbatim_content = reactive(teal.code :: get_code(req(decorated_output_q() ))),
455476 title = " Show R Code for Scatterplotmatrix"
456477 )
457478
@@ -470,7 +491,7 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
470491 card $ append_text(" Comment" , " header3" )
471492 card $ append_text(comment )
472493 }
473- card $ append_src(teal.code :: get_code(output_q( )))
494+ card $ append_src(teal.code :: get_code(req(decorated_output_q() )))
474495 card
475496 }
476497 teal.reporter :: simple_reporter_srv(" simple_reporter" , reporter = reporter , card_fun = card_fun )
0 commit comments