Skip to content

Commit cd04607

Browse files
committed
feat: do not decorate tables that are interactive
1 parent 9f00032 commit cd04607

File tree

4 files changed

+56
-83
lines changed

4 files changed

+56
-83
lines changed

NEWS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# teal.modules.general 0.4.1.9015
22

3+
### Breaking changes
4+
5+
- Removed the `table` object decoration in `tm_missing_data` and `tm_outliers` (#899).
6+
- Removed the `summary_table` and `test_table` object decoration in `tm_g_distribution` (#897).
7+
38
### Bug fixes
49

5-
- Fixes "Add to Report" functionality in `tm_outliers`, `tm_missing_data` and `tm_g_distribution` modules (#899 and #897). Table decorators in this modules use `rtables` as base object for decoration.
10+
- Fixes "Add to Report" functionality in `tm_outliers`, `tm_missing_data` and `tm_g_distribution` modules (#899 and #897).
611

712
# teal.modules.general 0.4.1
813

R/tm_g_distribution.R

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
#' This module generates the following objects, which can be modified in place using decorators::
3232
#' - `histogram_plot` (`ggplot`)
3333
#' - `qq_plot` (`ggplot`)
34-
#' - `summary_table` (`ElementaryTable` created with [rtables::df_to_tt()])
35-
#' - The decorated table is only shown in the reporter as it is presented as an interactive `DataTable` in the module.
36-
#' - `test_table` (`ElementaryTable` created with [rtables::df_to_tt()])
37-
#' - The decorated table is only shown in the reporter as it is presented as an interactive `DataTable` in the module.
3834
#'
3935
#' A Decorator is applied to the specific output using a named list of `teal_transform_module` objects.
4036
#' The name of this list corresponds to the name of the output to which the decorator is applied.
@@ -45,9 +41,7 @@
4541
#' ..., # arguments for module
4642
#' decorators = list(
4743
#' histogram_plot = teal_transform_module(...), # applied only to `histogram_plot` output
48-
#' qq_plot = teal_transform_module(...), # applied only to `qq_plot` output
49-
#' summary_table = teal_transform_module(...), # applied only to `summary_table` output
50-
#' test_table = teal_transform_module(...) # applied only to `test_table` output
44+
#' qq_plot = teal_transform_module(...) # applied only to `qq_plot` output
5145
#' )
5246
#' )
5347
#' ```
@@ -196,8 +190,7 @@ tm_g_distribution <- function(label = "Distribution Module",
196190
checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
197191
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
198192

199-
available_decorators <- c("histogram_plot", "qq_plot", "test_table", "summary_table")
200-
assert_decorators(decorators, names = available_decorators)
193+
assert_decorators(decorators, names = c("histogram_plot", "qq_plot"))
201194

202195
# End of assertions
203196

@@ -324,14 +317,6 @@ ui_distribution <- function(id, ...) {
324317
collapsed = FALSE
325318
)
326319
),
327-
ui_decorate_teal_data(
328-
ns("d_summary"),
329-
decorators = select_decorators(args$decorators, "summary_table")
330-
),
331-
ui_decorate_teal_data(
332-
ns("d_test"),
333-
decorators = select_decorators(args$decorators, "test_table")
334-
),
335320
conditionalPanel(
336321
condition = paste0("input['", ns("main_type"), "'] == 'Density'"),
337322
bslib::accordion_panel(
@@ -1286,14 +1271,17 @@ srv_distribution <- function(id,
12861271
# Summary table listing has to be created separately to allow for qenv join
12871272
output_summary_q <- reactive({
12881273
if (iv_r()$is_valid()) {
1289-
within(common_q(), summary_table <- rtables::df_to_tt(summary_table_data))
1274+
within(common_q(), {
1275+
summary_table <- rtables::df_to_tt(summary_table_data)
1276+
summary_table
1277+
})
12901278
} else {
12911279
within(
12921280
common_q(),
12931281
summary_table <- rtables::rtable(header = rtables::rheader(colnames(summary_table_data)))
12941282
)
12951283
}
1296-
})
1284+
})
12971285

12981286
output_test_q <- reactive({
12991287
# wrapped in if since could lead into validate error - we do want to continue
@@ -1304,7 +1292,10 @@ srv_distribution <- function(id,
13041292
test_table <- rtables::rtable(header = rtables::rheader("No data available in table"), rtables::rrow())
13051293
)
13061294
} else {
1307-
within(c(common_q(), test_q_out), test_table <- rtables::df_to_tt(test_table_data))
1295+
within(c(common_q(), test_q_out), {
1296+
test_table <- rtables::df_to_tt(test_table_data)
1297+
test_table
1298+
})
13081299
}
13091300
})
13101301

@@ -1322,47 +1313,42 @@ srv_distribution <- function(id,
13221313
expr = print(qq_plot)
13231314
)
13241315

1325-
decorated_output_summary_q <- srv_decorate_teal_data(
1326-
"d_summary",
1327-
data = output_summary_q,
1328-
decorators = select_decorators(decorators, "summary_table"),
1329-
expr = summary_table
1330-
)
1331-
1332-
decorated_output_test_q <- srv_decorate_teal_data(
1333-
"d_test",
1334-
data = output_test_q,
1335-
decorators = select_decorators(decorators, "test_table"),
1336-
expr = test_table
1337-
)
1338-
13391316
decorated_output_q <- reactive({
13401317
tab <- req(input$tabs) # tab is NULL upon app launch, hence will crash without this statement
13411318
test_q_out <- try(test_q(), silent = TRUE)
1342-
decorated_test_q_out <- decorated_output_test_q()
1319+
test_q_out <- output_test_q()
13431320

13441321
out_q <- switch(tab,
13451322
Histogram = decorated_output_dist_q(),
13461323
QQplot = decorated_output_qq_q()
13471324
)
1348-
c(out_q, decorated_output_summary_q(), decorated_test_q_out)
1325+
c(out_q, output_summary_q(), test_q_out)
13491326
})
13501327

13511328
dist_r <- reactive(req(decorated_output_dist_q())[["histogram_plot"]])
13521329

13531330
qq_r <- reactive(req(decorated_output_qq_q())[["qq_plot"]])
13541331

1355-
output$summary_table <- DT::renderDataTable(
1356-
expr = decorated_output_summary_q()[["summary_table_data"]],
1357-
options = list(
1358-
autoWidth = TRUE,
1359-
columnDefs = list(list(width = "200px", targets = "_all"))
1360-
),
1361-
rownames = FALSE
1362-
)
1332+
summary_r <- reactive({
1333+
q <- req(output_summary_q())
1334+
1335+
list(
1336+
html = DT::datatable(
1337+
q[["summary_table_data"]],
1338+
options = list(
1339+
autoWidth = TRUE,
1340+
columnDefs = list(list(width = "200px", targets = "_all"))
1341+
),
1342+
rownames = FALSE
1343+
),
1344+
report = q[["summary_table"]]
1345+
)
1346+
})
1347+
1348+
output$summary_table <- DT::renderDataTable(summary_r()[["html"]])
13631349

13641350
tests_r <- reactive({
1365-
q <- req(decorated_output_test_q())
1351+
q <- req(output_test_q())
13661352

13671353
list(
13681354
html = DT::datatable(q[["test_table_data"]]),
@@ -1386,7 +1372,7 @@ srv_distribution <- function(id,
13861372
brushing = FALSE
13871373
)
13881374

1389-
output$t_stats <- DT::renderDataTable(expr = tests_r()[["html"]])
1375+
output$t_stats <- DT::renderDataTable(tests_r()[["html"]])
13901376

13911377
# Render R code.
13921378
source_code_r <- reactive(teal.code::get_code(req(decorated_output_q())))
@@ -1413,7 +1399,7 @@ srv_distribution <- function(id,
14131399
card$append_plot(qq_r(), dim = pws2$dim())
14141400
}
14151401
card$append_text("Statistics table", "header3")
1416-
card$append_table(decorated_output_summary_q()[["summary_table"]])
1402+
card$append_table(summary_r()[["report"]])
14171403
tests_error <- tryCatch(expr = tests_r(), error = function(e) "error")
14181404
if (!identical(tests_error, "error")) {
14191405
card$append_text("Tests table", "header3")

R/tm_missing_data.R

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#' - `summary_plot` (`grob` created with [ggplot2::ggplotGrob()])
2424
#' - `combination_plot` (`grob` created with [ggplot2::ggplotGrob()])
2525
#' - `by_subject_plot` (`ggplot`)
26-
#' - `table` (`ElementaryTable` created with [rtables::df_to_tt()])
27-
#' - The decorated table is only shown in the reporter as it is presented as an interactive `DataTable` in the module.
2826
#'
2927
#' A Decorator is applied to the specific output using a named list of `teal_transform_module` objects.
3028
#' The name of this list corresponds to the name of the output to which the decorator is applied.
@@ -36,8 +34,7 @@
3634
#' decorators = list(
3735
#' summary_plot = teal_transform_module(...), # applied only to `summary_plot` output
3836
#' combination_plot = teal_transform_module(...), # applied only to `combination_plot` output
39-
#' by_subject_plot = teal_transform_module(...), # applied only to `by_subject_plot` output
40-
#' table = teal_transform_module(...) # applied only to `table` output
37+
#' by_subject_plot = teal_transform_module(...) # applied only to `by_subject_plot` output
4138
#' )
4239
#' )
4340
#' ```
@@ -149,8 +146,7 @@ tm_missing_data <- function(label = "Missing data",
149146
checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
150147
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
151148

152-
available_decorators <- c("summary_plot", "combination_plot", "by_subject_plot", "table")
153-
assert_decorators(decorators, names = available_decorators)
149+
assert_decorators(decorators, names = c("summary_plot", "combination_plot", "by_subject_plot"))
154150
# End of assertions
155151

156152
datanames_module <- if (identical(datanames, "all") || is.null(datanames)) {
@@ -430,8 +426,7 @@ encoding_missing_data <- function(id, summary_per_patient = FALSE, ggtheme, data
430426
choices = c("counts", "proportions"),
431427
selected = "counts",
432428
inline = TRUE
433-
),
434-
ui_decorate_teal_data(ns("dec_summary_table"), decorators = select_decorators(decorators, "table"))
429+
)
435430
),
436431
bslib::accordion(
437432
bslib::accordion_panel(
@@ -1144,7 +1139,10 @@ srv_missing_data <- function(id,
11441139
)
11451140
}
11461141

1147-
within(qenv, table <- rtables::df_to_tt(summary_data))
1142+
within(qenv, {
1143+
table <- rtables::df_to_tt(summary_data)
1144+
table
1145+
})
11481146
})
11491147

11501148
by_subject_plot_q <- reactive({
@@ -1286,13 +1284,6 @@ srv_missing_data <- function(id,
12861284
}
12871285
)
12881286

1289-
decorated_summary_table_q <- srv_decorate_teal_data(
1290-
id = "dec_summary_table",
1291-
data = summary_table_q,
1292-
decorators = select_decorators(decorators, "table"),
1293-
expr = table
1294-
)
1295-
12961287
decorated_by_subject_plot_q <- srv_decorate_teal_data(
12971288
id = "dec_by_subject_plot",
12981289
data = by_subject_plot_q,
@@ -1311,7 +1302,7 @@ srv_missing_data <- function(id,
13111302
})
13121303

13131304
summary_table_r <- reactive({
1314-
q <- req(decorated_summary_table_q())
1305+
q <- req(summary_table_q())
13151306

13161307
list(
13171308
html = if (length(input$variables_select) == 0) {
@@ -1366,7 +1357,7 @@ srv_missing_data <- function(id,
13661357
} else if (sum_type == "Combinations") {
13671358
decorated_combination_plot_q()
13681359
} else if (sum_type == "By Variable Levels") {
1369-
decorated_summary_table_q()
1360+
summary_table_q()
13701361
} else if (sum_type == "Grouped by Subject") {
13711362
decorated_by_subject_plot_q()
13721363
}
@@ -1404,7 +1395,7 @@ srv_missing_data <- function(id,
14041395
card$append_plot(combination_plot_r(), dim = pws2$dim())
14051396
} else if (sum_type == "By Variable Levels") {
14061397
card$append_text("Table", "header3")
1407-
if (nrow(decorated_summary_table_q()[["summary_data"]]) == 0L) {
1398+
if (nrow(summary_table_q()[["summary_data"]]) == 0L) {
14081399
card$append_text("No data available for table.")
14091400
} else {
14101401
card$append_table(summary_table_r()[["report"]])

R/tm_outliers.R

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#' - `box_plot` (`ggplot`)
2222
#' - `density_plot` (`ggplot`)
2323
#' - `cumulative_plot` (`ggplot`)
24-
#' - `table` (`ElementaryTable` created with [rtables::df_to_tt()])
25-
#' - The decorated table is only shown in the reporter as it is presented as an interactive `DataTable` in the module.
2624
#'
2725
#' A Decorator is applied to the specific output using a named list of `teal_transform_module` objects.
2826
#' The name of this list corresponds to the name of the output to which the decorator is applied.
@@ -34,8 +32,7 @@
3432
#' decorators = list(
3533
#' box_plot = teal_transform_module(...), # applied only to `box_plot` output
3634
#' density_plot = teal_transform_module(...), # applied only to `density_plot` output
37-
#' cumulative_plot = teal_transform_module(...), # applied only to `cumulative_plot` output
38-
#' table = teal_transform_module(...) # applied only to `table` output
35+
#' cumulative_plot = teal_transform_module(...) # applied only to `cumulative_plot` output
3936
#' )
4037
#' )
4138
#' ```
@@ -198,8 +195,7 @@ tm_outliers <- function(label = "Outliers Module",
198195
checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
199196
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
200197

201-
available_decorators <- c("box_plot", "density_plot", "cumulative_plot", "table")
202-
assert_decorators(decorators, names = available_decorators)
198+
assert_decorators(decorators, names = c("box_plot", "density_plot", "cumulative_plot"))
203199
# End of assertions
204200

205201
# Make UI args
@@ -369,7 +365,6 @@ ui_outliers <- function(id, ...) {
369365
decorators = select_decorators(args$decorators, "cumulative_plot")
370366
)
371367
),
372-
ui_decorate_teal_data(ns("d_table"), decorators = select_decorators(args$decorators, "table")),
373368
bslib::accordion_panel(
374369
title = "Plot settings",
375370
selectInput(
@@ -754,7 +749,10 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
754749
}
755750

756751
# Generate decoratable object from data
757-
qenv <- within(qenv, table <- rtables::df_to_tt(summary_data))
752+
qenv <- within(qenv, {
753+
table <- rtables::df_to_tt(summary_data)
754+
table
755+
})
758756

759757
if (length(categorical_var) > 0 && nrow(qenv[["ANL_OUTLIER"]]) > 0) {
760758
shinyjs::show("order_by_outlier")
@@ -1058,14 +1056,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
10581056
c(box_plot_q, density_plot_q, cumulative_plot_q)
10591057
)
10601058

1061-
decorated_final_q_no_table <- reactive(decorated_q[[req(current_tab_r())]]())
1062-
1063-
decorated_final_q <- srv_decorate_teal_data(
1064-
"d_table",
1065-
data = decorated_final_q_no_table,
1066-
decorators = select_decorators(decorators, "table"),
1067-
expr = table
1068-
)
1059+
decorated_final_q <- reactive(decorated_q[[req(current_tab_r())]]())
10691060

10701061
summary_table_r <- reactive({
10711062
q <- req(decorated_final_q())

0 commit comments

Comments
 (0)