Skip to content

Commit 0d1cd5e

Browse files
m7praverissimogithub-actions[bot]Copilot
authored
đź“‘ Reporter Refactor: Adds support for new teal_report and teal_card class (#1392)
Closes #1376 --------- Signed-off-by: Marcin <[email protected]> Signed-off-by: AndrĂ© VerĂ­ssimo <[email protected]> Co-authored-by: AndrĂ© VerĂ­ssimo <[email protected]> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
1 parent 2dbb0a8 commit 0d1cd5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+752
-1240
lines changed

‎DESCRIPTION‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ URL: https://insightsengineering.github.io/teal.modules.clinical/,
3232
BugReports:
3333
https://github.com/insightsengineering/teal.modules.clinical/issues
3434
Depends:
35-
R (>= 4.4.0),
36-
teal (>= 1.0.0),
35+
R (>= 4.4),
36+
teal (>= 1.0.0.9003),
3737
teal.transform (>= 0.7.0),
3838
tern (>= 0.9.9)
3939
Imports:
@@ -60,7 +60,7 @@ Imports:
6060
teal.code (>= 0.7.0),
6161
teal.data (>= 0.8.0),
6262
teal.logger (>= 0.4.0),
63-
teal.reporter (>= 0.5.0),
63+
teal.reporter (>= 0.5.0.9001),
6464
teal.widgets (>= 0.5.0),
6565
tern.gee (>= 0.1.5),
6666
tern.mmrm (>= 0.3.3),
@@ -82,6 +82,9 @@ Suggests:
8282
VignetteBuilder:
8383
knitr,
8484
rmarkdown
85+
Remotes:
86+
insightsengineering/teal.reporter,
87+
insightsengineering/teal
8588
Config/Needs/verdepcheck: insightsengineering/teal,
8689
insightsengineering/teal.slice, insightsengineering/teal.transform,
8790
insightsengineering/tern, tidymodels/broom, mllg/checkmate,

‎R/tm_a_gee.R‎

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ template_a_gee <- function(output_table,
159159
#' To learn more please refer to the vignette
160160
#' `vignette("transform-module-output", package = "teal")` or the [`teal::teal_transform_module()`] documentation.
161161
#'
162+
#' @inheritSection teal::example_module Reporting
163+
#'
162164
#' @examplesShinylive
163165
#' library(teal.modules.clinical)
164166
#' interactive <- function() TRUE
@@ -299,10 +301,6 @@ ui_gee <- function(id, ...) {
299301
teal.widgets::table_with_settings_ui(ns("table"))
300302
),
301303
encoding = tags$div(
302-
### Reporter
303-
teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"),
304-
tags$br(), tags$br(),
305-
###
306304
tags$label("Encodings", class = "text-primary"), tags$br(),
307305
teal.transform::datanames_input(a[c("arm_var", "paramcd", "id_var", "visit_var", "cov_var", "aval_var")]),
308306
teal.transform::data_extract_ui(
@@ -402,8 +400,6 @@ ui_gee <- function(id, ...) {
402400

403401
srv_gee <- function(id,
404402
data,
405-
filter_panel_api,
406-
reporter,
407403
dataname,
408404
parentname,
409405
arm_var,
@@ -419,8 +415,6 @@ srv_gee <- function(id,
419415
plot_width,
420416
basic_table_args,
421417
decorators) {
422-
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
423-
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
424418
checkmate::assert_class(data, "reactive")
425419
checkmate::assert_class(isolate(data()), "teal_data")
426420

@@ -510,7 +504,14 @@ srv_gee <- function(id,
510504
)
511505

512506
anl_q <- reactive({
513-
data() %>%
507+
obj <- data()
508+
teal.reporter::teal_card(obj) <-
509+
c(
510+
teal.reporter::teal_card("# Generalized Estimating Equations (GEE) Analysis Table"),
511+
teal.reporter::teal_card(obj),
512+
teal.reporter::teal_card("## Module's code")
513+
)
514+
obj %>%
514515
teal.code::eval_code(as.expression(anl_inputs()$expr)) %>%
515516
teal.code::eval_code(as.expression(adsl_inputs()$expr))
516517
})
@@ -564,7 +565,16 @@ srv_gee <- function(id,
564565
cor_struct = input$cor_struct,
565566
basic_table_args = basic_table_args
566567
)
567-
teal.code::eval_code(merged$anl_q(), as.expression(unlist(my_calls)))
568+
569+
table_type <- switch(input$output_table,
570+
"t_gee_cov" = "Residual Covariance Matrix Estimate",
571+
"t_gee_coef" = "Model Coefficients",
572+
"t_gee_lsmeans" = "LS Means Estimates"
573+
)
574+
575+
obj <- merged$anl_q()
576+
teal.reporter::teal_card(obj) <- c(teal.reporter::teal_card(obj), paste("## ", table_type, "Table"))
577+
teal.code::eval_code(obj, as.expression(unlist(my_calls)))
568578
})
569579

570580
output$gee_title <- renderText({
@@ -602,30 +612,6 @@ srv_gee <- function(id,
602612
title = label
603613
)
604614

605-
### REPORTER
606-
if (with_reporter) {
607-
card_fun <- function(comment, label) {
608-
card <- teal::report_card_template(
609-
title = "Generalized Estimating Equations (GEE) Analysis Table",
610-
label = label,
611-
with_filter = with_filter,
612-
filter_panel_api = filter_panel_api
613-
)
614-
table_type <- switch(input$output_table,
615-
"t_gee_cov" = "Residual Covariance Matrix Estimate",
616-
"t_gee_coef" = "Model Coefficients",
617-
"t_gee_lsmeans" = "LS Means Estimates"
618-
)
619-
card$append_text(paste(table_type, "Table"), "header3")
620-
card$append_table(table_r())
621-
if (!comment == "") {
622-
card$append_text("Comment", "header3")
623-
card$append_text(comment)
624-
}
625-
card$append_src(source_code_r())
626-
card
627-
}
628-
teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun)
629-
}
615+
decorated_table_q
630616
})
631617
}

‎R/tm_a_mmrm.R‎

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ template_mmrm_plots <- function(fit_name,
493493
#' To learn more please refer to the vignette
494494
#' `vignette("transform-module-output", package = "teal")` or the [`teal::teal_transform_module()`] documentation.
495495
#'
496+
#' @inheritSection teal::example_module Reporting
497+
#'
496498
#' @examplesShinylive
497499
#' library(teal.modules.clinical)
498500
#' interactive <- function() TRUE
@@ -520,7 +522,7 @@ template_mmrm_plots <- function(fit_name,
520522
#' AVISITN = rank(AVISITN) %>%
521523
#' as.factor() %>%
522524
#' as.numeric() %>%
523-
#' as.factor() #' making consecutive numeric factor
525+
#' as.factor() # making consecutive numeric factor
524526
#' )
525527
#' })
526528
#' join_keys(data) <- default_cdisc_join_keys[names(data)]
@@ -677,10 +679,6 @@ ui_mmrm <- function(id, ...) {
677679
teal.widgets::plot_with_settings_ui(id = ns("mmrm_plot"))
678680
),
679681
encoding = tags$div(
680-
### Reporter
681-
teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"),
682-
tags$br(), tags$br(),
683-
###
684682
tags$label("Encodings", class = "text-primary"), tags$br(),
685683
teal.transform::datanames_input(a[c("arm_var", "paramcd", "id_var", "visit_var", "cov_var", "aval_var")]),
686684
bslib::accordion(
@@ -901,8 +899,6 @@ ui_mmrm <- function(id, ...) {
901899
#' @keywords internal
902900
srv_mmrm <- function(id,
903901
data,
904-
reporter,
905-
filter_panel_api,
906902
dataname,
907903
parentname,
908904
arm_var,
@@ -920,8 +916,6 @@ srv_mmrm <- function(id,
920916
basic_table_args,
921917
ggplot2_args,
922918
decorators) {
923-
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
924-
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
925919
checkmate::assert_class(data, "reactive")
926920
checkmate::assert_class(isolate(data()), "teal_data")
927921

@@ -1040,7 +1034,14 @@ srv_mmrm <- function(id,
10401034
})
10411035

10421036
anl_q <- reactive({
1043-
data_with_tern_options_r() %>%
1037+
obj <- data_with_tern_options_r()
1038+
teal.reporter::teal_card(obj) <-
1039+
c(
1040+
teal.reporter::teal_card("# Mixed Model Repeated Measurements (MMRM) Analysis"),
1041+
teal.reporter::teal_card(obj),
1042+
teal.reporter::teal_card("## Module's code")
1043+
)
1044+
obj %>%
10441045
teal.code::eval_code(code = as.expression(anl_inputs()$expr)) %>%
10451046
teal.code::eval_code(code = as.expression(adsl_merge_inputs()$expr))
10461047
})
@@ -1412,7 +1413,9 @@ srv_mmrm <- function(id,
14121413
basic_table_args = basic_table_args
14131414
)
14141415

1415-
teal.code::eval_code(qenv, as.expression(mmrm_table))
1416+
obj <- qenv
1417+
teal.reporter::teal_card(obj) <- c(teal.reporter::teal_card(obj), "## Table")
1418+
teal.code::eval_code(obj, as.expression(mmrm_table))
14161419
})
14171420

14181421
# Endpoint:
@@ -1482,7 +1485,9 @@ srv_mmrm <- function(id,
14821485
diagnostic_plot = diagnostic_args,
14831486
ggplot2_args = ggplot2_args
14841487
)
1485-
teal.code::eval_code(qenv, as.expression(mmrm_plot_expr))
1488+
obj <- qenv
1489+
teal.reporter::teal_card(obj) <- c(teal.reporter::teal_card(obj), "## Plot")
1490+
teal.code::eval_code(obj, as.expression(mmrm_plot_expr))
14861491
})
14871492

14881493
decorated_tables_q <- lapply(
@@ -1568,36 +1573,8 @@ srv_mmrm <- function(id,
15681573
title = label
15691574
)
15701575

1571-
### REPORTER
1572-
if (with_reporter) {
1573-
card_fun <- function(comment, label) {
1574-
card <- teal::report_card_template(
1575-
title = "Mixed Model Repeated Measurements (MMRM) Analysis",
1576-
label = label,
1577-
description = paste(
1578-
"Mixed Models procedure analyzes results from repeated measures designs",
1579-
"in which the outcome is continuous and measured at fixed time points"
1580-
),
1581-
with_filter = with_filter,
1582-
filter_panel_api = filter_panel_api
1583-
)
1584-
if (!is.null(table_r())) {
1585-
card$append_text("Table", "header3")
1586-
card$append_table(table_r())
1587-
}
1588-
if (!is.null(plot_r())) {
1589-
card$append_text("Plot", "header3")
1590-
card$append_plot(plot_r(), dim = pws$dim())
1591-
}
1592-
if (!comment == "") {
1593-
card$append_text("Comment", "header3")
1594-
card$append_text(comment)
1595-
}
1596-
card$append_src(source_code_r())
1597-
card
1598-
}
1599-
teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun)
1600-
}
1601-
###
1576+
set_chunk_dims(pws, reactive({
1577+
decorated_objs_q[[obj_ix_r()]]()
1578+
}))
16021579
})
16031580
}

‎R/tm_g_barchart_simple.R‎

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#' To learn more please refer to the vignette
4141
#' `vignette("transform-module-output", package = "teal")` or the [`teal::teal_transform_module()`] documentation.
4242
#'
43+
#' @inheritSection teal::example_module Reporting
44+
#'
4345
#' @examplesShinylive
4446
#' library(teal.modules.clinical)
4547
#' interactive <- function() TRUE
@@ -248,10 +250,6 @@ ui_g_barchart_simple <- function(id, ...) {
248250
uiOutput(ns("table"), style = "overflow-y: scroll; max-height: 250px;")
249251
),
250252
encoding = tags$div(
251-
### Reporter
252-
teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"),
253-
tags$br(), tags$br(),
254-
###
255253
tags$label("Encodings", class = "text-primary"), tags$br(),
256254
teal.transform::datanames_input(args[c("x", "fill", "x_facet", "y_facet")]),
257255
if (!is.null(args$x)) {
@@ -367,8 +365,6 @@ ui_g_barchart_simple <- function(id, ...) {
367365
#' @keywords internal
368366
srv_g_barchart_simple <- function(id,
369367
data,
370-
reporter,
371-
filter_panel_api,
372368
x,
373369
fill,
374370
x_facet,
@@ -378,8 +374,6 @@ srv_g_barchart_simple <- function(id,
378374
plot_width,
379375
ggplot2_args,
380376
decorators) {
381-
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
382-
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
383377
checkmate::assert_class(data, "reactive")
384378
checkmate::assert_class(isolate(data()), "teal_data")
385379

@@ -438,8 +432,14 @@ srv_g_barchart_simple <- function(id,
438432
)
439433

440434
anl_q <- reactive({
441-
data() %>%
442-
teal.code::eval_code(as.expression(anl_inputs()$expr))
435+
obj <- data()
436+
teal.reporter::teal_card(obj) <-
437+
c(
438+
teal.reporter::teal_card("# Barchart"),
439+
teal.reporter::teal_card(obj),
440+
teal.reporter::teal_card("## Module's code")
441+
)
442+
obj %>% teal.code::eval_code(as.expression(anl_inputs()$expr))
443443
})
444444

445445
count_q <- reactive({
@@ -538,17 +538,17 @@ srv_g_barchart_simple <- function(id,
538538
)
539539

540540
ANL <- count_q()[["ANL"]]
541-
542-
all_q <- count_q() %>%
541+
obj <- count_q() %>%
543542
teal.code::eval_code(substitute(
544543
env = list(groupby_vars = paste(groupby_vars, collapse = ", ")),
545544
plot_title <- sprintf(
546545
"Number of patients (total N = %s) for each combination of (%s)",
547546
nrow(ANL),
548547
groupby_vars
549548
)
550-
)) %>%
551-
teal.code::eval_code(code = plot_call)
549+
))
550+
teal.reporter::teal_card(obj) <- c(teal.reporter::teal_card(obj), "## Plot")
551+
teal.code::eval_code(obj, code = plot_call)
552552
})
553553

554554
decorated_all_q_code <- srv_decorate_teal_data(
@@ -602,27 +602,7 @@ srv_g_barchart_simple <- function(id,
602602
title = label
603603
)
604604

605-
### REPORTER
606-
if (with_reporter) {
607-
card_fun <- function(comment, label) {
608-
card <- teal::report_card_template(
609-
title = "Barchart Plot",
610-
label = label,
611-
with_filter = with_filter,
612-
filter_panel_api = filter_panel_api
613-
)
614-
card$append_text("Plot", "header3")
615-
card$append_plot(plot_r(), dim = pws$dim())
616-
if (!comment == "") {
617-
card$append_text("Comment", "header3")
618-
card$append_text(comment)
619-
}
620-
card$append_src(source_code_r())
621-
card
622-
}
623-
teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun)
624-
}
625-
###
605+
set_chunk_dims(pws, decorated_all_q_code)
626606
})
627607
}
628608

0 commit comments

Comments
 (0)