Skip to content

Commit 09066b9

Browse files
Fixes failing "Add to Report" for modules that have DT table visualization (#1411)
# Pull Request - Fixes #1404 ### Changes description - Reverts changes from #1350 - Decorated objects are `rlistings` or `rtables`, module output is `DT` - Adds documentation explicitly saying what is being decorated - Uses a pattern of `table_r` that contains 2 elements (report and html) --------- Signed-off-by: André Veríssimo <[email protected]> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 6adc08a commit 09066b9

11 files changed

+157
-322
lines changed

NEWS.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
### Enhancements
44
* Added argument `conf_type` to module `tm_g_km` to allow users to set a confidence interval type for median survival time estimation.
5-
6-
### Enhancements
75
* Added `denom` argument in `tm_t_binary_outcome` module.
86

97
### Bug fixes
108
* Fixed bug in `tm_t_events` to return sorted table (#1393).
9+
* Fixed "Add to Report" failures in `tm_g_pp_adverse_events`, `tm_g_pp_therapy`, `tm_t_pp_basic_info`, `tm_t_pp_laboratory` and `tm_t_pp_prior_medication` modules (#1404).
10+
11+
### Breaking changes
12+
13+
* Removed the `table` object decoration in `tm_g_pp_adverse_events`, `tm_g_pp_therapy` (#1404).
14+
* Deprecated the `decorators` argument in `tm_t_pp_basic_info`, `tm_t_pp_laboratory` and `tm_t_pp_prior_medication` (#1404).
1115

1216
# teal.modules.clinical 0.10.0
1317

R/tm_g_pp_adverse_events.R

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ template_adverse_events <- function(dataname = "ANL",
5858
dplyr::where(~ inherits(., what = "difftime")), ~ as.double(., units = "auto")
5959
)
6060
)
61-
table_output <- DT::datatable(table_data)
6261
},
6362
env = list(
6463
dataname = as.name(dataname),
@@ -183,7 +182,6 @@ template_adverse_events <- function(dataname = "ANL",
183182
#'
184183
#' This module generates the following objects, which can be modified in place using decorators::
185184
#' - `plot` (`ggplot`)
186-
#' - `table` (`datatables` - output of `DT::datatable()`)
187185
#'
188186
#' A Decorator is applied to the specific output using a named list of `teal_transform_module` objects.
189187
#' The name of this list corresponds to the name of the output to which the decorator is applied.
@@ -193,8 +191,7 @@ template_adverse_events <- function(dataname = "ANL",
193191
#' tm_g_pp_adverse_events(
194192
#' ..., # arguments for module
195193
#' decorators = list(
196-
#' plot = teal_transform_module(...), # applied only to `plot` output
197-
#' table = teal_transform_module(...) # applied only to `table` output
194+
#' plot = teal_transform_module(...) # applied only to `plot` output
198195
#' )
199196
#' )
200197
#' ```
@@ -310,7 +307,7 @@ tm_g_pp_adverse_events <- function(label,
310307
checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE)
311308
checkmate::assert_class(post_output, classes = "shiny.tag", null.ok = TRUE)
312309
checkmate::assert_class(ggplot2_args, "ggplot2_args")
313-
assert_decorators(decorators, names = c("plot", "table"))
310+
assert_decorators(decorators, names = "plot")
314311

315312
args <- as.list(environment())
316313
data_extract_list <- list(
@@ -432,7 +429,6 @@ ui_g_adverse_events <- function(id, ...) {
432429
is_single_dataset = is_single_dataset_value
433430
)
434431
),
435-
ui_decorate_teal_data(ns("d_table"), decorators = select_decorators(ui_args$decorators, "table")),
436432
ui_decorate_teal_data(ns("d_plot"), decorators = select_decorators(ui_args$decorators, "plot")),
437433
bslib::accordion_panel(
438434
title = "Plot settings",
@@ -594,36 +590,26 @@ srv_g_adverse_events <- function(id,
594590
# Allow for the table and plot qenv to be joined
595591
table_q <- reactive({
596592
req(all_q())
597-
teal.code::eval_code(all_q(), "table <- table_output")
593+
within(all_q(), {
594+
table <- rtables::df_to_tt(table_data)
595+
table
596+
})
598597
})
599598
plot_q <- reactive({
600599
req(all_q())
601-
teal.code::eval_code(all_q(), "plot <- plot_output")
600+
within(all_q(), plot <- plot_output)
602601
})
603602

604-
decorated_all_q_table <- srv_decorate_teal_data(
605-
"d_table",
606-
data = table_q,
607-
decorators = select_decorators(decorators, "table"),
608-
expr = table
609-
)
610-
611603
decorated_all_q_plot <- srv_decorate_teal_data(
612604
"d_plot",
613605
data = plot_q,
614606
decorators = select_decorators(decorators, "plot"),
615607
expr = plot
616608
)
617609

618-
table_r <- reactive({
619-
req(decorated_all_q_table())
620-
621-
decorated_all_q_table()[["table"]]
622-
})
623-
624610
plot_r <- reactive({
625611
req(iv_r()$is_valid(), decorated_all_q_plot())
626-
decorated_all_q_plot()[["plot"]]
612+
req(decorated_all_q_plot())[["plot"]]
627613
})
628614

629615
pws <- teal.widgets::plot_with_settings_srv(
@@ -633,13 +619,22 @@ srv_g_adverse_events <- function(id,
633619
width = plot_width
634620
)
635621

636-
output$table <- DT::renderDataTable(
637-
expr = table_r(),
638-
options = list(pageLength = input$table_rows)
639-
)
622+
table_r <- reactive({
623+
q <- req(table_q())
624+
625+
list(
626+
html = DT::datatable(
627+
data = q[["table_data"]],
628+
options = list(pageLength = input$table_rows)
629+
),
630+
report = q[["table"]]
631+
)
632+
})
633+
634+
output$table <- DT::renderDataTable(table_r()[["html"]])
640635

641636
decorated_all_q <- reactive(
642-
c(decorated_all_q_table(), decorated_all_q_plot())
637+
c(table_q(), decorated_all_q_plot())
643638
)
644639

645640
# Render R code
@@ -660,7 +655,7 @@ srv_g_adverse_events <- function(id,
660655
filter_panel_api = filter_panel_api
661656
)
662657
card$append_text("Table", "header3")
663-
card$append_table(table_r())
658+
card$append_table(table_r()[["report"]])
664659
card$append_text("Plot", "header3")
665660
card$append_plot(plot_r(), dim = pws$dim())
666661
if (!comment == "") {

R/tm_g_pp_therapy.R

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ template_therapy <- function(dataname = "ANL",
6565

6666
dataname[setdiff(cols_to_include, names(dataname))] <- NA
6767

68-
table <- dataname %>%
68+
table_data <- dataname %>%
6969
dplyr::filter(atirel %in% c("CONCOMITANT", "PRIOR")) %>% # removed PRIOR_CONCOMITANT
7070
dplyr::select(dplyr::all_of(cols_to_include)) %>%
7171
dplyr::filter(!is.na(cmdecod)) %>%
@@ -84,8 +84,8 @@ template_therapy <- function(dataname = "ANL",
8484
teal.data::col_labels(dataname, fill = TRUE)[c(cmindc_char, cmdecod_char)], "Dosage",
8585
teal.data::col_labels(dataname, fill = TRUE)[c(cmstdy_char, cmendy_char)]
8686
))
87-
88-
table <- DT::datatable(table)
87+
table <- rtables::df_to_tt(table_data)
88+
table
8989
}, env = list(
9090
dataname = as.name(dataname),
9191
atirel = as.name(atirel),
@@ -244,8 +244,7 @@ template_therapy <- function(dataname = "ANL",
244244
#'
245245
#' This module generates the following objects, which can be modified in place using decorators::
246246
#' - `plot` (`ggplot`)
247-
#' - `table` (`datatables` - output of `DT::datatable()`)
248-
#'
247+
249248
#' A Decorator is applied to the specific output using a named list of `teal_transform_module` objects.
250249
#' The name of this list corresponds to the name of the output to which the decorator is applied.
251250
#' See code snippet below:
@@ -254,8 +253,7 @@ template_therapy <- function(dataname = "ANL",
254253
#' tm_g_pp_therapy(
255254
#' ..., # arguments for module
256255
#' decorators = list(
257-
#' plot = teal_transform_module(...), # applied only to `plot` output
258-
#' table = teal_transform_module(...) # applied only to `table` output
256+
#' plot = teal_transform_module(...) # applied only to `plot` output
259257
#' )
260258
#' )
261259
#' ```
@@ -396,7 +394,7 @@ tm_g_pp_therapy <- function(label,
396394
checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE)
397395
checkmate::assert_class(post_output, classes = "shiny.tag", null.ok = TRUE)
398396
checkmate::assert_class(ggplot2_args, "ggplot2_args")
399-
assert_decorators(decorators, names = c("plot", "table"))
397+
assert_decorators(decorators, names = "plot")
400398

401399
args <- as.list(environment())
402400
data_extract_list <- list(
@@ -535,7 +533,6 @@ ui_g_therapy <- function(id, ...) {
535533
data_extract_spec = ui_args$cmendy,
536534
is_single_dataset = is_single_dataset_value
537535
),
538-
ui_decorate_teal_data(ns("d_table"), decorators = select_decorators(ui_args$decorators, "table")),
539536
ui_decorate_teal_data(ns("d_plot"), decorators = select_decorators(ui_args$decorators, "plot")),
540537
bslib::accordion_panel(
541538
title = "Plot settings",
@@ -701,30 +698,30 @@ srv_g_therapy <- function(id,
701698
paste("<h5><b>Patient ID:", all_q()[["pt_id"]], "</b></h5>")
702699
})
703700

704-
decorated_all_q_table <- srv_decorate_teal_data(
705-
"d_table",
706-
data = all_q,
707-
decorators = select_decorators(decorators, "table"),
708-
expr = table
709-
)
701+
table_r <- reactive({
702+
q <- req(all_q())
710703

711-
output$therapy_table <- DT::renderDataTable(
712-
expr = {
713-
decorated_all_q_table()[["table"]]
714-
},
715-
options = list(pageLength = input$therapy_table_rows)
716-
)
704+
list(
705+
html = DT::datatable(
706+
data = q[["table_data"]],
707+
options = list(pageLength = input$therapy_table_rows)
708+
),
709+
report = q[["table"]]
710+
)
711+
})
712+
713+
output$therapy_table <- DT::renderDataTable(table_r()[["html"]])
717714

718715
decorated_all_q_plot <- srv_decorate_teal_data(
719716
"d_plot",
720-
data = decorated_all_q_table,
717+
data = all_q,
721718
decorators = select_decorators(decorators, "plot"),
722719
expr = plot
723720
)
724721

725722
plot_r <- reactive({
726723
req(iv_r()$is_valid())
727-
decorated_all_q_plot()[["plot"]]
724+
req(decorated_all_q_plot())[["plot"]]
728725
})
729726

730727
pws <- teal.widgets::plot_with_settings_srv(
@@ -752,7 +749,7 @@ srv_g_therapy <- function(id,
752749
filter_panel_api = filter_panel_api
753750
)
754751
card$append_text("Table", "header3")
755-
card$append_table(all_q()[["table"]])
752+
card$append_table(table_r()[["report"]])
756753
card$append_text("Plot", "header3")
757754
card$append_plot(plot_r(), dim = pws$dim())
758755
if (!comment == "") {

0 commit comments

Comments
 (0)