Skip to content

Commit 929f45f

Browse files
committed
feat: tm_g_response
1 parent 8e262c3 commit 929f45f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

R/tm_g_response.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,14 @@ tm_g_response <- function(label = "Response Plot",
201201
checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
202202
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
203203

204-
checkmate::assert_list(decorators, "teal_transform_module", null.ok = TRUE)
204+
if (checkmate::test_list(decorators, "teal_transform_module", null.ok = TRUE)) {
205+
decorators <- if (checkmate::test_names(names(decorators), subset.of = c("default", "plot"))) {
206+
lapply(decorators, list)
207+
} else {
208+
list(default = decorators)
209+
}
210+
}
211+
assert_decorators(decorators, null.ok = TRUE, names = c("default", "plot"))
205212
# End of assertions
206213

207214
# Make UI args
@@ -285,7 +292,7 @@ ui_g_response <- function(id, ...) {
285292
selected = ifelse(args$freq, "frequency", "density"),
286293
justified = TRUE
287294
),
288-
ui_transform_teal_data(ns("decorator"), transformators = args$decorators),
295+
ui_decorate_teal_data(ns("decorator"), decorators = subset_decorators("plot", args$decorators)),
289296
teal.widgets::panel_group(
290297
teal.widgets::panel_item(
291298
title = "Plot settings",
@@ -552,13 +559,14 @@ srv_g_response <- function(id,
552559
teal.code::eval_code(qenv, plot_call)
553560
})
554561

555-
decorated_output_q <- srv_transform_teal_data(id = "decorator", data = output_q, transformators = decorators)
562+
decorated_output_plot_q <- srv_decorate_teal_data(
563+
id = "decorator",
564+
data = output_q,
565+
decorators = subset_decorators("plot", decorators),
566+
expr = print(plot)
567+
)
556568

557-
decorated_output_plot_q <- reactive(within(decorated_output_q(), print(plot)))
558-
plot_r <- reactive({
559-
req(output_q()) # Ensure original errors are displayed
560-
decorated_output_plot_q()[["plot"]]
561-
})
569+
plot_r <- reactive(req(decorated_output_plot_q())[["plot"]])
562570

563571
# Insert the plot into a plot_with_settings module from teal.widgets
564572
pws <- teal.widgets::plot_with_settings_srv(

0 commit comments

Comments
 (0)