Skip to content

Commit 7c4996c

Browse files
committed
fix after teal
1 parent bf87833 commit 7c4996c

File tree

2 files changed

+39
-72
lines changed

2 files changed

+39
-72
lines changed

R/tm_a_regression.R

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#'
3737
#' It takes the form of `c(value, min, max)` and it is passed to the `value_min_max`
3838
#' argument in `teal.widgets::optionalSliderInputValMinMax`.
39-
#' @param decorator (`teal_transform_module`, `language`, `function`)
39+
#' @param decorators (`list` of `teal_transform_module`)
4040
#'
4141
#' @templateVar ggnames `r regression_names`
4242
#' @template ggplot2_args_multi
@@ -162,14 +162,13 @@ tm_a_regression <- function(label = "Regression Analysis",
162162
default_plot_type = 1,
163163
default_outlier_label = "USUBJID",
164164
label_segment_threshold = c(0.5, 0, 10),
165-
decorator = list(default = teal_transform_module())) {
165+
decorators = list(default = teal_transform_module())) {
166166
message("Initializing tm_a_regression")
167167

168168
# Normalize the parameters
169169
if (inherits(regressor, "data_extract_spec")) regressor <- list(regressor)
170170
if (inherits(response, "data_extract_spec")) response <- list(response)
171171
if (inherits(ggplot2_args, "ggplot2_args")) ggplot2_args <- list(default = ggplot2_args)
172-
decorate_objs <- lapply(decorator, FUN = decorate_teal_data, output_name = "g")
173172

174173
# Start of assertions
175174
checkmate::assert_string(label)
@@ -217,6 +216,7 @@ tm_a_regression <- function(label = "Regression Analysis",
217216
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
218217
checkmate::assert_choice(default_plot_type, seq.int(1L, length(plot_choices)))
219218
checkmate::assert_string(default_outlier_label)
219+
checkmate::assert_list(decorators, "teal_transform_module")
220220

221221
if (length(label_segment_threshold) == 1) {
222222
checkmate::assert_numeric(label_segment_threshold, any.missing = FALSE, finite = TRUE)
@@ -243,15 +243,15 @@ tm_a_regression <- function(label = "Regression Analysis",
243243
label = label,
244244
server = srv_a_regression,
245245
ui = ui_a_regression,
246-
ui_args = c(args, decorate_objs = decorate_objs),
246+
ui_args = args,
247247
server_args = c(
248248
data_extract_list,
249249
list(
250250
plot_height = plot_height,
251251
plot_width = plot_width,
252252
default_outlier_label = default_outlier_label,
253253
ggplot2_args = ggplot2_args,
254-
decorate_objs = decorate_objs
254+
decorators = decorators
255255
)
256256
),
257257
datanames = teal.transform::get_extract_datanames(data_extract_list)
@@ -261,7 +261,7 @@ tm_a_regression <- function(label = "Regression Analysis",
261261
}
262262

263263
# UI function for the regression module
264-
ui_a_regression <- function(id, decorate_objs, ...) {
264+
ui_a_regression <- function(id, decorators, ...) {
265265
ns <- NS(id)
266266
args <- list(...)
267267
is_single_dataset_value <- teal.transform::is_single_dataset(args$regressor, args$response)
@@ -298,37 +298,37 @@ ui_a_regression <- function(id, decorate_objs, ...) {
298298
conditionalPanel(
299299
condition = "input.plot_type == 'Response vs Regressor'",
300300
ns = ns,
301-
ui_transform_data(ns("d_0"), transforms = decorate_objs[[1]])
301+
ui_teal_transform_module(ns("d_0"), transforms = decorators[[1]])
302302
),
303303
conditionalPanel(
304304
condition = "input.plot_type == 'Residuals vs Fitted'",
305305
ns = ns,
306-
ui_transform_data(ns("d_1"), transforms = decorate_objs[[1]])
306+
ui_teal_transform_module(ns("d_1"), transforms = decorators[[1]])
307307
),
308308
conditionalPanel(
309309
condition = "input.plot_type == 'Normal Q-Q'",
310310
ns = ns,
311-
ui_transform_data(ns("d_2"), transforms = decorate_objs[[1]])
311+
ui_teal_transform_module(ns("d_2"), transforms = decorators[[1]])
312312
),
313313
conditionalPanel(
314314
condition = "input.plot_type == 'Scale-Location'",
315315
ns = ns,
316-
ui_transform_data(ns("d_3"), transforms = decorate_objs[[1]])
316+
ui_teal_transform_module(ns("d_3"), transforms = decorators[[1]])
317317
),
318318
conditionalPanel(
319319
condition = "input.plot_type == 'Cook\\'s distance'",
320320
ns = ns,
321-
ui_transform_data(ns("d_4"), transforms = decorate_objs[[1]])
321+
ui_teal_transform_module(ns("d_4"), transforms = decorators[[1]])
322322
),
323323
conditionalPanel(
324324
condition = "input.plot_type == 'Residuals vs Leverage'",
325325
ns = ns,
326-
ui_transform_data(ns("d_5"), transforms = decorate_objs[[1]])
326+
ui_teal_transform_module(ns("d_5"), transforms = decorators[[1]])
327327
),
328328
conditionalPanel(
329329
condition = "input.plot_type == 'Cook\\'s dist vs Leverage'",
330330
ns = ns,
331-
ui_transform_data(ns("d_6"), transforms = decorate_objs[[1]])
331+
ui_teal_transform_module(ns("d_6"), transforms = decorators[[1]])
332332
),
333333
),
334334
checkboxInput(ns("show_outlier"), label = "Display outlier labels", value = TRUE),
@@ -417,7 +417,7 @@ srv_a_regression <- function(id,
417417
plot_width,
418418
ggplot2_args,
419419
default_outlier_label,
420-
decorate_objs) {
420+
decorators) {
421421
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
422422
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
423423
checkmate::assert_class(data, "reactive")
@@ -1006,13 +1006,13 @@ srv_a_regression <- function(id,
10061006
)
10071007
})
10081008

1009-
decorated_output_0 <- srv_transform_data(id = "d_0", data = output_plot_0, transforms = decorate_objs[[1]])
1010-
decorated_output_1 <- srv_transform_data(id = "d_1", data = output_plot_1, transforms = decorate_objs[[1]])
1011-
decorated_output_2 <- srv_transform_data(id = "d_2", data = output_plot_2, transforms = decorate_objs[[1]])
1012-
decorated_output_3 <- srv_transform_data(id = "d_3", data = output_plot_3, transforms = decorate_objs[[1]])
1013-
decorated_output_4 <- srv_transform_data(id = "d_4", data = output_plot_4, transforms = decorate_objs[[1]])
1014-
decorated_output_5 <- srv_transform_data(id = "d_5", data = output_plot_5, transforms = decorate_objs[[1]])
1015-
decorated_output_6 <- srv_transform_data(id = "d_6", data = output_plot_6, transforms = decorate_objs[[1]])
1009+
decorated_output_0 <- srv_teal_transform_module(id = "d_0", data = output_plot_0, transforms = decorators[[1]])
1010+
decorated_output_1 <- srv_teal_transform_module(id = "d_1", data = output_plot_1, transforms = decorators[[1]])
1011+
decorated_output_2 <- srv_teal_transform_module(id = "d_2", data = output_plot_2, transforms = decorators[[1]])
1012+
decorated_output_3 <- srv_teal_transform_module(id = "d_3", data = output_plot_3, transforms = decorators[[1]])
1013+
decorated_output_4 <- srv_teal_transform_module(id = "d_4", data = output_plot_4, transforms = decorators[[1]])
1014+
decorated_output_5 <- srv_teal_transform_module(id = "d_5", data = output_plot_5, transforms = decorators[[1]])
1015+
decorated_output_6 <- srv_teal_transform_module(id = "d_6", data = output_plot_6, transforms = decorators[[1]])
10161016

10171017

10181018
output_q <- reactive({

R/tm_outliers.R

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
#' Specifies variable(s) to be analyzed for outliers.
1212
#' @param categorical_var (`data_extract_spec` or `list` of multiple `data_extract_spec`) optional,
1313
#' specifies the categorical variable(s) to split the selected outlier variables on.
14-
#' @param table_decorator (`teal_transform_module`, `language` or `function`) optional,
14+
#' @param table_decorator (`list` of `teal_transform_module`) optional,
1515
#' decorator for the table.
16-
#' @param boxplot_decorator (`teal_transform_module`, `language` or `function`) optional,
16+
#' @param boxplot_decorator (`list` of `teal_transform_module`) optional,
1717
#' decorator for the box plot.
18-
#' @param violin_decorator (`teal_transform_module`, `language` or `function`) optional,
18+
#' @param violin_decorator (`list` of `teal_transform_module`) optional,
1919
#' decorator for the violing plot.
20-
#' @param density_decorator (`teal_transform_module`, `language` or `function`) optional,
20+
#' @param density_decorator (`list` of `teal_transform_module`) optional,
2121
#' decorator for the density plot.
22-
#' @param cum_dist_decorator (`teal_transform_module`, `language` or `function`) optional,
22+
#' @param cum_dist_decorator (`list` of `teal_transform_module`) optional,
2323
#' decorator for the cumulative distribution plot.
2424
#'
2525
#' @templateVar ggnames "Boxplot","Density Plot","Cumulative Distribution Plot"
@@ -32,40 +32,14 @@
3232
#' The module lets app developers do it by allowing them to execute arbitrary R code
3333
#' that modifies the objects displayed by the module.
3434
#'
35-
#' The decorating parameters accept one of the three types of objects as decorators:
36-
#' * `teal_transform_module`
37-
#' * `language`
38-
#' * `function` of the output object.
39-
#'
40-
#' The module will execute the code contained in either of the objects just before
35+
#' The module will execute the code contained in [`teal_transform_module`] before
4136
#' rendering the outputs in the application. This lets app developers modify
4237
#' features like: titles, labels, sizes, limits, etc. of the rendered tables
4338
#' and plots.
4439
#'
45-
#' The app developer can pass either of the types. See examples for the proper
46-
#' use of each of the type of the decorator.
47-
#'
48-
#' IMPORTANT
49-
#' The `language` and `teal_transform_module` decorators are required by the module
50-
#' to overwrite the binding of the output, otherwise the effect of the decorator
51-
#' is not going to be visible. E.g.:
52-
#'
53-
#' ```{r}
54-
#' # The module uses `g` variable for the plot
55-
#'
56-
#' # Will work
57-
#' lang_dec <- quote({
58-
#' g <- g + ggplot2::ggtitle("A new title")
59-
#' })
60-
#'
61-
#' # Will not work because the decorater overwrites `plot` instead of `g`
62-
#' lang_dec <- quote({
63-
#' plot <- g + ggplot2::ggtitle("A new title")
64-
#' })
65-
#' ```
66-
#'
67-
#' The app developer can discover the bindings used for the outputs by inspecting
68-
#' the R code generated by the module.
40+
#' The app developer should apply decorators carefuly with respect to the module's internal
41+
#' object names. To modify an output, app developer needs to find out the name of the table or plot
42+
#' that is being modified by the code in the `teal_transform_module` list element.
6943
#'
7044
#' @examples
7145
#' library(teal.widgets)
@@ -214,12 +188,6 @@ tm_outliers <- function(label = "Outliers Module",
214188
if (inherits(categorical_var, "data_extract_spec")) categorical_var <- list(categorical_var)
215189
if (inherits(ggplot2_args, "ggplot2_args")) ggplot2_args <- list(default = ggplot2_args)
216190

217-
table_decorator <- decorate_teal_data(table_decorator, output_name = "summary_table")
218-
boxplot_decorator <- decorate_teal_data(boxplot_decorator, output_name = "g")
219-
violin_decorator <- decorate_teal_data(violin_decorator, output_name = "g")
220-
density_decorator <- decorate_teal_data(density_decorator, output_name = "g")
221-
cum_dist_decorator <- decorate_teal_data(cum_dist_decorator, output_name = "g")
222-
223191
# Start of assertions
224192
checkmate::assert_string(label)
225193
checkmate::assert_list(outlier_var, types = "data_extract_spec")
@@ -284,12 +252,11 @@ ui_outliers <- function(id, ...) {
284252
ns <- NS(id)
285253
is_single_dataset_value <- teal.transform::is_single_dataset(args$outlier_var, args$categorical_var)
286254

287-
288255
teal.widgets::standard_layout(
289256
output = teal.widgets::white_small_well(
290257
uiOutput(ns("total_outliers")),
291258
DT::dataTableOutput(ns("summary_table")),
292-
ui_transform_data(ns("table_decorator"), transforms = args$table_decorator),
259+
ui_teal_transform_module(ns("table_decorator"), transforms = args$table_decorator),
293260
uiOutput(ns("total_missing")),
294261
tags$br(), tags$hr(),
295262
tabsetPanel(
@@ -298,22 +265,22 @@ ui_outliers <- function(id, ...) {
298265
"Boxplot",
299266
conditionalPanel(
300267
condition = sprintf("input['%s'] == 'Box plot'", ns("boxplot_alts")),
301-
ui_transform_data(ns("boxplot_decorator"), args$boxplot_decorator)
268+
ui_teal_transform_module(ns("boxplot_decorator"), args$boxplot_decorator)
302269
),
303270
conditionalPanel(
304271
condition = sprintf("input['%s'] == 'Violin plot'", ns("boxplot_alts")),
305-
ui_transform_data(ns("violin_decorator"), args$violin_decorator)
272+
ui_teal_transform_module(ns("violin_decorator"), args$violin_decorator)
306273
),
307274
teal.widgets::plot_with_settings_ui(id = ns("box_plot"))
308275
),
309276
tabPanel(
310277
"Density Plot",
311-
ui_transform_data(ns("density_decorator"), args$density_decorator),
278+
ui_teal_transform_module(ns("density_decorator"), args$density_decorator),
312279
teal.widgets::plot_with_settings_ui(id = ns("density_plot"))
313280
),
314281
tabPanel(
315282
"Cumulative Distribution Plot",
316-
ui_transform_data(ns("cum_dist_decorator"), args$cum_dist_decorator),
283+
ui_teal_transform_module(ns("cum_dist_decorator"), args$cum_dist_decorator),
317284
teal.widgets::plot_with_settings_ui(id = ns("cum_density_plot"))
318285
)
319286
),
@@ -1042,10 +1009,10 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
10421009
)
10431010
})
10441011

1045-
decorated_boxplot_q <- srv_transform_data("boxplot_decorator", data = boxplot_q, transforms = decorators$boxplot)
1046-
decorated_violin_q <- srv_transform_data("violin_decorator", data = boxplot_q, transforms = decorators$violin)
1047-
decorated_density_plot_q <- srv_transform_data("density_decorator", data = density_plot_q, transforms = decorators$density)
1048-
decorated_cumulative_plot_q <- srv_transform_data("cum_dist_decorator", data = cumulative_plot_q, transforms = decorators$cum_dist)
1012+
decorated_boxplot_q <- srv_teal_transform_module("boxplot_decorator", data = boxplot_q, transforms = decorators$boxplot)
1013+
decorated_violin_q <- srv_teal_transform_module("violin_decorator", data = boxplot_q, transforms = decorators$violin)
1014+
decorated_density_plot_q <- srv_teal_transform_module("density_decorator", data = density_plot_q, transforms = decorators$density)
1015+
decorated_cumulative_plot_q <- srv_teal_transform_module("cum_dist_decorator", data = cumulative_plot_q, transforms = decorators$cum_dist)
10491016

10501017
final_q <- reactive({
10511018
req(input$tabs)

0 commit comments

Comments
 (0)