Skip to content

Commit d045e7b

Browse files
committed
elo
1 parent 6bb26f5 commit d045e7b

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

R/tm_outliers.R

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#'
5353
#' ```{r}
5454
#' # The module uses `g` variable for the plot
55-
#'
55+
#'
5656
#' # Will work
5757
#' lang_dec <- quote({
5858
#' g <- g + ggplot2::ggtitle("A new title")
@@ -182,12 +182,12 @@
182182
#' module_decorator <- teal_transform_module(
183183
#' ui = function(id) NULL,
184184
#' srv = function(id, data) {
185-
#' within(
186-
#' data,
187-
#' {
188-
#' g <- g + ggplot2::ggtitle("A new title")
189-
#' }
190-
#' )
185+
#' within(
186+
#' data,
187+
#' {
188+
#' g <- g + ggplot2::ggtitle("A new title")
189+
#' }
190+
#' )
191191
#' }
192192
#' )
193193
#'
@@ -213,7 +213,7 @@ tm_outliers <- function(label = "Outliers Module",
213213
if (inherits(outlier_var, "data_extract_spec")) outlier_var <- list(outlier_var)
214214
if (inherits(categorical_var, "data_extract_spec")) categorical_var <- list(categorical_var)
215215
if (inherits(ggplot2_args, "ggplot2_args")) ggplot2_args <- list(default = ggplot2_args)
216-
216+
217217
table_decorator <- decorate_teal_data(table_decorator, output_name = "summary_table")
218218
boxplot_decorator <- decorate_teal_data(boxplot_decorator, output_name = "g")
219219
violin_decorator <- decorate_teal_data(violin_decorator, output_name = "g")
@@ -266,8 +266,9 @@ tm_outliers <- function(label = "Outliers Module",
266266
server_args = c(
267267
data_extract_list,
268268
list(
269-
plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args,
270-
decorators = list(table = table_decorator, boxplot = boxplot_decorator, violin = violin_decorator, density = density_decorator, cum_dist = cum_dist_decorator))
269+
plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args,
270+
decorators = list(table = table_decorator, boxplot = boxplot_decorator, violin = violin_decorator, density = density_decorator, cum_dist = cum_dist_decorator)
271+
)
271272
),
272273
ui = ui_outliers,
273274
ui_args = c(args),
@@ -288,7 +289,7 @@ ui_outliers <- function(id, ...) {
288289
output = teal.widgets::white_small_well(
289290
uiOutput(ns("total_outliers")),
290291
DT::dataTableOutput(ns("summary_table")),
291-
ui_teal_data(ns("table_decorator"), args$table_decorator),
292+
ui_transform_data(ns("table_decorator"), transforms = args$table_decorator),
292293
uiOutput(ns("total_missing")),
293294
tags$br(), tags$hr(),
294295
tabsetPanel(
@@ -297,22 +298,22 @@ ui_outliers <- function(id, ...) {
297298
"Boxplot",
298299
conditionalPanel(
299300
condition = sprintf("input['%s'] == 'Box plot'", ns("boxplot_alts")),
300-
ui_teal_data(ns("boxplot_decorator"), args$boxplot_decorator)
301+
ui_transform_data(ns("boxplot_decorator"), args$boxplot_decorator)
301302
),
302303
conditionalPanel(
303-
condition = sprintf("input['%s'] == 'Violin plot'", ns("boxplot_alts")),
304-
ui_teal_data(ns("violin_decorator"), args$violin_decorator)
304+
condition = sprintf("input['%s'] == 'Violin plot'", ns("boxplot_alts")),
305+
ui_transform_data(ns("violin_decorator"), args$violin_decorator)
305306
),
306307
teal.widgets::plot_with_settings_ui(id = ns("box_plot"))
307308
),
308309
tabPanel(
309310
"Density Plot",
310-
ui_teal_data(ns("density_decorator"), args$density_decorator),
311+
ui_transform_data(ns("density_decorator"), args$density_decorator),
311312
teal.widgets::plot_with_settings_ui(id = ns("density_plot"))
312313
),
313314
tabPanel(
314315
"Cumulative Distribution Plot",
315-
ui_teal_data(ns("cum_dist_decorator"), args$cum_dist_decorator),
316+
ui_transform_data(ns("cum_dist_decorator"), args$cum_dist_decorator),
316317
teal.widgets::plot_with_settings_ui(id = ns("cum_density_plot"))
317318
)
318319
),
@@ -766,7 +767,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
766767
qenv
767768
})
768769

769-
decorated_table_q <- srv_teal_data(id = "table_decorator", data = common_code_q, data_module = decorators$table, modules = module())
770+
decorated_table_q <- srv_transform_data("table_decorator", data = common_code_q, transforms = decorators$table)
770771
output$summary_table <- DT::renderDataTable(
771772
expr = {
772773
if (iv_r()$is_valid()) {
@@ -1044,15 +1045,20 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
10441045
teal.code::eval_code(quote(print(g)))
10451046
})
10461047

1048+
decorated_boxplot_q <- srv_transform_data("boxplot_decorator", data = boxplot_q, transforms = decorators$boxplot)
1049+
decorated_violin_r <- srv_transform_data("violin_decorator", data = undecorated_boxplot_r, transforms = decorators$violin)
1050+
decorated_density_plot_q <- srv_transform_data("density_decorator", data = density_plot_q, transforms = decorators$density)
1051+
cumulative_plot_r <- srv_transform_data("cum_dist_decorator", data = undecorated_cumulative_plot_r, transforms = decorators$cum_dist)
1052+
10471053
final_q <- reactive({
10481054
req(input$tabs)
10491055
tab_type <- input$tabs
10501056
result_q <- if (tab_type == "Boxplot") {
1051-
boxplot_q()
1057+
decorated_boxplot_q()
10521058
} else if (tab_type == "Density Plot") {
1053-
density_plot_q()
1059+
decorated_density_plot_q()
10541060
} else if (tab_type == "Cumulative Distribution Plot") {
1055-
cumulative_plot_q()
1061+
decorated_cumulative_plot_q()
10561062
}
10571063
# used to display table when running show-r-code code
10581064
# added after the plots so that a change in selected columns doesn't affect
@@ -1122,12 +1128,11 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
11221128
}
11231129
})
11241130

1125-
undecorated_boxplot_r <- reactive({
1131+
boxplot_r <- reactive({
11261132
teal::validate_inputs(iv_r())
1127-
boxplot_q()[["g"]]
1133+
decorated_boxplot_q()[["g"]]
11281134
})
1129-
decorated_boxplot_r <- srv_teal_data(id = "boxplot_decorator", data = undecorated_boxplot_r, data_module = decorators$boxplot, modules = module())
1130-
decorated_violin_r <- srv_teal_data(id = "violin_decorator", data = undecorated_boxplot_r, data_module = decorators$violin, modules = module())
1135+
11311136
boxplot_r <- reactive({
11321137
req(input$boxplot_alts)
11331138
if (input$boxplot_alts == "Box plot") {
@@ -1136,16 +1141,17 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
11361141
decorated_violin_r()
11371142
}
11381143
})
1139-
undecorated_density_plot_r <- reactive({
1144+
1145+
density_plot_r <- reactive({
11401146
teal::validate_inputs(iv_r())
1141-
density_plot_q()[["g"]]
1147+
decorated_density_plot_q()[["g"]]
11421148
})
1143-
density_plot_r <- srv_teal_data(id = "density_decorator", data = undecorated_density_plot_r, data_module = decorators$density, modules = module())
1144-
undecorated_cumulative_plot_r <- reactive({
1149+
1150+
cumulative_plot_r <- reactive({
11451151
teal::validate_inputs(iv_r())
11461152
cumulative_plot_q()[["g"]]
11471153
})
1148-
cumulative_plot_r <- srv_teal_data(id = "cum_dist_decorator", data = undecorated_cumulative_plot_r, data_module = decorators$cum_dist, modules = module())
1154+
11491155

11501156
box_pws <- teal.widgets::plot_with_settings_srv(
11511157
id = "box_plot",

0 commit comments

Comments
 (0)