1212# ' @param x_facet (`data_extract_spec`)\cr row-wise faceting groups.
1313# ' @param y_facet (`data_extract_spec`)\cr column-wise faceting groups.
1414# ' @param plot_options (`list`)\cr list of plot options.
15+ # ' @param decorators `r roxygen_decorators_param("tm_g_barchart_simple")`
1516# '
1617# ' @inherit module_arguments return seealso
1718# '
19+ # ' @section Decorating `tm_g_barchart_simple`:
20+ # '
21+ # ' This module generates the following objects, which can be modified in place using decorators:
22+ # ' - `plot` (`ggplot2`)
23+ # '
24+ # ' For additional details and examples of decorators, refer to the vignette
25+ # ' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation.
26+ # '
1827# ' @examplesShinylive
1928# ' library(teal.modules.clinical)
2029# ' interactive <- function() TRUE
@@ -146,7 +155,8 @@ tm_g_barchart_simple <- function(x = NULL,
146155 plot_width = NULL ,
147156 pre_output = NULL ,
148157 post_output = NULL ,
149- ggplot2_args = teal.widgets :: ggplot2_args()) {
158+ ggplot2_args = teal.widgets :: ggplot2_args(),
159+ decorators = NULL ) {
150160 message(" Initializing tm_g_barchart_simple" )
151161 checkmate :: assert_string(label )
152162 checkmate :: assert_list(plot_options , null.ok = TRUE )
@@ -171,6 +181,8 @@ tm_g_barchart_simple <- function(x = NULL,
171181 checkmate :: assert_class(pre_output , classes = " shiny.tag" , null.ok = TRUE )
172182 checkmate :: assert_class(post_output , classes = " shiny.tag" , null.ok = TRUE )
173183 checkmate :: assert_class(ggplot2_args , " ggplot2_args" )
184+ decorators <- normalize_decorators(decorators )
185+ assert_decorators(decorators , names = " plot" , null.ok = TRUE )
174186
175187 plot_options <- utils :: modifyList(
176188 list (stacked = FALSE ), # default
@@ -190,7 +202,8 @@ tm_g_barchart_simple <- function(x = NULL,
190202 y_facet = y_facet ,
191203 plot_height = plot_height ,
192204 plot_width = plot_width ,
193- ggplot2_args = ggplot2_args
205+ ggplot2_args = ggplot2_args ,
206+ decorators = decorators
194207 ),
195208 datanames = " all"
196209 )
@@ -249,6 +262,7 @@ ui_g_barchart_simple <- function(id, ...) {
249262 is_single_dataset = is_single_dataset_value
250263 )
251264 },
265+ ui_decorate_teal_data(ns(" decorator" ), decorators = select_decorators(args $ decorators , " plot" )),
252266 teal.widgets :: panel_group(
253267 teal.widgets :: panel_item(
254268 " Additional plot settings" ,
@@ -336,7 +350,8 @@ srv_g_barchart_simple <- function(id,
336350 y_facet ,
337351 plot_height ,
338352 plot_width ,
339- ggplot2_args ) {
353+ ggplot2_args ,
354+ decorators ) {
340355 with_reporter <- ! missing(reporter ) && inherits(reporter , " Reporter" )
341356 with_filter <- ! missing(filter_panel_api ) && inherits(filter_panel_api , " FilterPanelAPI" )
342357 checkmate :: assert_class(data , " reactive" )
@@ -506,13 +521,16 @@ srv_g_barchart_simple <- function(id,
506521 )
507522 )) %> %
508523 teal.code :: eval_code(code = plot_call )
509-
510- # explicitly calling print on the plot inside the qenv evaluates
511- # the ggplot call and therefore catches errors
512- teal.code :: eval_code(all_q , code = quote(print(plot )))
513524 })
514525
515- plot_r <- reactive(all_q()[[" plot" ]])
526+ decorated_all_q_code <- srv_decorate_teal_data(
527+ " decorator" ,
528+ data = all_q ,
529+ decorators = select_decorators(decorators , " plot" ),
530+ expr = print(plot )
531+ )
532+
533+ plot_r <- reactive(decorated_all_q_code()[[" plot" ]])
516534
517535 output $ table <- renderTable({
518536 req(iv_r()$ is_valid())
@@ -550,7 +568,7 @@ srv_g_barchart_simple <- function(id,
550568
551569 teal.widgets :: verbatim_popup_srv(
552570 id = " rcode" ,
553- verbatim_content = reactive(teal.code :: get_code(all_q( ))),
571+ verbatim_content = reactive(teal.code :: get_code(req(decorated_all_q_code() ))),
554572 title = " Bar Chart"
555573 )
556574
@@ -569,7 +587,7 @@ srv_g_barchart_simple <- function(id,
569587 card $ append_text(" Comment" , " header3" )
570588 card $ append_text(comment )
571589 }
572- card $ append_src(teal.code :: get_code(all_q( )))
590+ card $ append_src(teal.code :: get_code(req(decorated_all_q_code() )))
573591 card
574592 }
575593 teal.reporter :: simple_reporter_srv(" simple_reporter" , reporter = reporter , card_fun = card_fun )
0 commit comments