3030# '
3131# ' @inherit shared_params return
3232# '
33+ # ' @section Decorating `tm_g_scatterplot`:
34+ # '
35+ # ' This module generates the following objects, which can be modified in place using decorators:
36+ # ' - `plot` (`ggplot2`)
37+ # '
38+ # ' For additional details and examples of decorators, refer to the vignette
39+ # ' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation.
40+ # '
41+ # '
3342# ' @examplesShinylive
3443# ' library(teal.modules.general)
3544# ' interactive <- function() TRUE
@@ -229,7 +238,8 @@ tm_g_scatterplot <- function(label = "Scatterplot",
229238 pre_output = NULL ,
230239 post_output = NULL ,
231240 table_dec = 4 ,
232- ggplot2_args = teal.widgets :: ggplot2_args()) {
241+ ggplot2_args = teal.widgets :: ggplot2_args(),
242+ decorators = NULL ) {
233243 message(" Initializing tm_g_scatterplot" )
234244
235245 # Requires Suggested packages
@@ -297,6 +307,7 @@ tm_g_scatterplot <- function(label = "Scatterplot",
297307
298308 checkmate :: assert_scalar(table_dec )
299309 checkmate :: assert_class(ggplot2_args , " ggplot2_args" )
310+ checkmate :: assert_list(decorators , " teal_transform_module" , null.ok = TRUE )
300311 # End of assertions
301312
302313 # Make UI args
@@ -318,7 +329,13 @@ tm_g_scatterplot <- function(label = "Scatterplot",
318329 ui_args = args ,
319330 server_args = c(
320331 data_extract_list ,
321- list (plot_height = plot_height , plot_width = plot_width , table_dec = table_dec , ggplot2_args = ggplot2_args )
332+ list (
333+ plot_height = plot_height ,
334+ plot_width = plot_width ,
335+ table_dec = table_dec ,
336+ ggplot2_args = ggplot2_args ,
337+ decorators = decorators
338+ )
322339 ),
323340 datanames = teal.transform :: get_extract_datanames(data_extract_list )
324341 )
@@ -413,6 +430,7 @@ ui_g_scatterplot <- function(id, ...) {
413430 is_single_dataset = is_single_dataset_value
414431 )
415432 },
433+ ui_transform_teal_data(ns(" decorator" ), transformators = args $ decorators ),
416434 teal.widgets :: panel_group(
417435 teal.widgets :: panel_item(
418436 title = " Plot settings" ,
@@ -491,7 +509,8 @@ srv_g_scatterplot <- function(id,
491509 plot_height ,
492510 plot_width ,
493511 table_dec ,
494- ggplot2_args ) {
512+ ggplot2_args ,
513+ decorators ) {
495514 with_reporter <- ! missing(reporter ) && inherits(reporter , " Reporter" )
496515 with_filter <- ! missing(filter_panel_api ) && inherits(filter_panel_api , " FilterPanelAPI" )
497516 checkmate :: assert_class(data , " reactive" )
@@ -981,13 +1000,17 @@ srv_g_scatterplot <- function(id,
9811000 )
9821001 }
9831002
984- plot_call <- substitute(expr = p <- plot_call , env = list (plot_call = plot_call ))
1003+ plot_call <- substitute(expr = plot <- plot_call , env = list (plot_call = plot_call ))
9851004
986- teal.code :: eval_code(plot_q , plot_call ) %> %
987- teal.code :: eval_code(quote(print(p )))
1005+ teal.code :: eval_code(plot_q , plot_call )
9881006 })
9891007
990- plot_r <- reactive(output_q()[[" p" ]])
1008+ decorated_output_q <- srv_transform_teal_data(id = " decorator" , data = output_q , transformators = decorators )
1009+ decorated_output_plot_q <- reactive(within(decorated_output_q(), print(plot )))
1010+ plot_r <- reactive({
1011+ req(output_q()) # Ensure original errors are displayed
1012+ decorated_output_plot_q()[[" plot" ]]
1013+ })
9911014
9921015 # Insert the plot into a plot_with_settings module from teal.widgets
9931016 pws <- teal.widgets :: plot_with_settings_srv(
@@ -1028,7 +1051,7 @@ srv_g_scatterplot <- function(id,
10281051
10291052 teal.widgets :: verbatim_popup_srv(
10301053 id = " rcode" ,
1031- verbatim_content = reactive(teal.code :: get_code(output_q( ))),
1054+ verbatim_content = reactive(teal.code :: get_code(req(decorated_output_plot_q() ))),
10321055 title = " R Code for scatterplot"
10331056 )
10341057
@@ -1047,7 +1070,7 @@ srv_g_scatterplot <- function(id,
10471070 card $ append_text(" Comment" , " header3" )
10481071 card $ append_text(comment )
10491072 }
1050- card $ append_src(teal.code :: get_code(output_q( )))
1073+ card $ append_src(teal.code :: get_code(req(decorated_output_plot_q() )))
10511074 card
10521075 }
10531076 teal.reporter :: simple_reporter_srv(" simple_reporter" , reporter = reporter , card_fun = card_fun )
0 commit comments