Skip to content

Commit 4c4d214

Browse files
committed
add req statement so that when srv_teal_transform_data returns NULL you see error from original teal_data
1 parent 3d48ec6 commit 4c4d214

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

R/tm_a_regression.R

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ tm_a_regression <- function(label = "Regression Analysis",
156156
default_plot_type = 1,
157157
default_outlier_label = "USUBJID",
158158
label_segment_threshold = c(0.5, 0, 10),
159-
decorators = list(default = teal_transform_module())) {
159+
decorators = NULL) {
160160
message("Initializing tm_a_regression")
161161

162162
# Normalize the parameters
@@ -210,7 +210,7 @@ tm_a_regression <- function(label = "Regression Analysis",
210210
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
211211
checkmate::assert_choice(default_plot_type, seq.int(1L, length(plot_choices)))
212212
checkmate::assert_string(default_outlier_label)
213-
checkmate::assert_list(decorators, "teal_transform_module")
213+
checkmate::assert_list(decorators, "teal_transform_module", null.ok = TRUE)
214214

215215
if (length(label_segment_threshold) == 1) {
216216
checkmate::assert_numeric(label_segment_threshold, any.missing = FALSE, finite = TRUE)
@@ -1010,6 +1010,19 @@ srv_a_regression <- function(id,
10101010

10111011

10121012
output_q <- reactive({
1013+
teal::validate_inputs(iv_r())
1014+
switch(input$plot_type,
1015+
"Response vs Regressor" = output_plot_0(),
1016+
"Residuals vs Fitted" = output_plot_1(),
1017+
"Normal Q-Q" = output_plot_2(),
1018+
"Scale-Location" = output_plot_3(),
1019+
"Cook's distance" = output_plot_4(),
1020+
"Residuals vs Leverage" = output_plot_5(),
1021+
"Cook's dist vs Leverage" = output_plot_6()
1022+
)
1023+
})
1024+
1025+
decorated_output_q <- reactive({
10131026
teal::validate_inputs(iv_r())
10141027
switch(input$plot_type,
10151028
"Response vs Regressor" = decorated_output_0(),
@@ -1022,8 +1035,14 @@ srv_a_regression <- function(id,
10221035
)
10231036
})
10241037

1025-
fitted <- reactive(output_q()[["fit"]])
1026-
plot_r <- reactive(output_q()[["plot"]])
1038+
fitted <- reactive({
1039+
req(output_q())
1040+
decorated_output_q()[["fit"]]
1041+
})
1042+
plot_r <- reactive({
1043+
req(output_q())
1044+
decorated_output_q()[["plot"]]
1045+
})
10271046

10281047
# Insert the plot into a plot_with_settings module from teal.widgets
10291048
pws <- teal.widgets::plot_with_settings_srv(
@@ -1043,7 +1062,7 @@ srv_a_regression <- function(id,
10431062

10441063
teal.widgets::verbatim_popup_srv(
10451064
id = "rcode",
1046-
verbatim_content = reactive(teal.code::get_code(req(output_q()))),
1065+
verbatim_content = reactive(teal.code::get_code(req(decorated_output_q()))),
10471066
title = "R code for the regression plot",
10481067
)
10491068

@@ -1062,7 +1081,7 @@ srv_a_regression <- function(id,
10621081
card$append_text("Comment", "header3")
10631082
card$append_text(comment)
10641083
}
1065-
card$append_src(teal.code::get_code(req(output_q())))
1084+
card$append_src(teal.code::get_code(req(decorated_output_q())))
10661085
card
10671086
}
10681087
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)

R/utils.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#' with text placed before the output to put the output into context. For example a title.
2626
#' @param post_output (`shiny.tag`) optional, text or UI element to be displayed after the module's output,
2727
#' adding context or further instructions. Elements like `shiny::helpText()` are useful.
28-
#' @param decorators `r lifecycle::badge("experimental")` (`list` of `teal_transform_module`) optional,
29-
#' decorator for tables or plots included in the module.
28+
#' @param decorators `r lifecycle::badge("experimental")` (`list` of `teal_transform_module` or `NULL`) optional,
29+
#' if not `NULL`, decorator for tables or plots included in the module.
3030
#'
3131
#' @param alpha (`integer(1)` or `integer(3)`) optional, specifies point opacity.
3232
#' - When the length of `alpha` is one: the plot points will have a fixed opacity.

0 commit comments

Comments
 (0)