Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce decorators for tm_t events by grade #1276

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions R/tm_t_events_by_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ template_events_by_grade <- function(dataname,
expr = {
pruned_and_sorted_result <- pruned_result %>%
sort_at_path(path = term_var, scorefun = scorefun, decreasing = TRUE)
pruned_and_sorted_result
},
env = list(
term_var = term_var,
Expand All @@ -356,11 +355,6 @@ template_events_by_grade <- function(dataname,
)
)
)

sort_list <- add_expr(
sort_list,
quote(pruned_and_sorted_result)
)
}
y$sort <- bracket_expr(sort_list)

Expand Down Expand Up @@ -769,11 +763,6 @@ template_events_col_by_grade <- function(dataname,
prune_list,
prune_pipe
)
prune_list <- add_expr(
prune_list,
quote(pruned_and_sorted_result)
)

y$prune <- bracket_expr(prune_list)

y
Expand All @@ -788,9 +777,18 @@ template_events_col_by_grade <- function(dataname,
#' @inheritParams template_events_col_by_grade
#' @param col_by_grade (`logical`)\cr whether to display the grading groups in nested columns.
#' @param grading_groups (`list`)\cr named list of grading groups used when `col_by_grade = TRUE`.
#' @param decorators `r roxygen_decorators_param("tm_t_events_by_grade")`
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @inherit module_arguments return seealso
#'
#' @section Decorating `tm_t_events_by_grade`:
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
#'
#' This module generates the following objects, which can be modified in place using decorators:
#' - `table` (`TableTree` as created from `rtables::build_table`)
#'
#' For additional details and examples of decorators, refer to the vignette
#' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation.
#'
#' @export
#'
#' @examplesShinylive
Expand Down Expand Up @@ -865,7 +863,8 @@ tm_t_events_by_grade <- function(label,
drop_arm_levels = TRUE,
pre_output = NULL,
post_output = NULL,
basic_table_args = teal.widgets::basic_table_args()) {
basic_table_args = teal.widgets::basic_table_args(),
decorators = NULL) {
message("Initializing tm_t_events_by_grade")
checkmate::assert_string(label)
checkmate::assert_string(dataname)
Expand All @@ -883,6 +882,8 @@ tm_t_events_by_grade <- function(label,
checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE)
checkmate::assert_class(post_output, classes = "shiny.tag", null.ok = TRUE)
checkmate::assert_class(basic_table_args, "basic_table_args")
decorators <- normalize_decorators(decorators)
assert_decorators(decorators, "table", null.ok = TRUE)

args <- as.list(environment())

Expand All @@ -907,7 +908,8 @@ tm_t_events_by_grade <- function(label,
total_label = total_label,
grading_groups = grading_groups,
na_level = na_level,
basic_table_args = basic_table_args
basic_table_args = basic_table_args,
decorators = decorators
)
),
datanames = teal.transform::get_extract_datanames(data_extract_list)
Expand Down Expand Up @@ -962,6 +964,7 @@ ui_t_events_by_grade <- function(id, ...) {
"Display grade groupings in nested columns",
value = a$col_by_grade
),
ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(a$decorators, "table")),
teal.widgets::panel_group(
teal.widgets::panel_item(
"Additional table settings",
Expand Down Expand Up @@ -1017,7 +1020,8 @@ srv_t_events_by_grade <- function(id,
drop_arm_levels,
total_label,
na_level,
basic_table_args) {
basic_table_args,
decorators) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
Expand Down Expand Up @@ -1202,9 +1206,25 @@ srv_t_events_by_grade <- function(id,
teal.code::eval_code(merged$anl_q(), as.expression(unlist(my_calls)))
})


table_renamed_q <- reactive({
if (length(table_q()[["pruned_and_sorted_result"]])) {
averissimo marked this conversation as resolved.
Show resolved Hide resolved
out <- within(table_q(), {table <- pruned_and_sorted_result})
} else {
out <- within(table_q(), {table <- pruned_result})
}
out
})

decorated_table_q <- srv_decorate_teal_data(
id = "decorator",
data = table_renamed_q,
decorators = select_decorators(decorators, "table"),
expr = table
)
# Outputs to render.
table_r <- reactive({
table_q()[["pruned_and_sorted_result"]]
decorated_table_q()[["table"]]
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
})

teal.widgets::table_with_settings_srv(
Expand All @@ -1215,7 +1235,7 @@ srv_t_events_by_grade <- function(id,
# Render R code.
teal.widgets::verbatim_popup_srv(
id = "rcode",
verbatim_content = reactive(teal.code::get_code(table_q())),
verbatim_content = reactive(teal.code::get_code(req(decorated_table_q()))),
title = label
)

Expand All @@ -1234,7 +1254,7 @@ srv_t_events_by_grade <- function(id,
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(teal.code::get_code(table_q()))
card$append_src(teal.code::get_code(req(decorated_table_q())))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
21 changes: 20 additions & 1 deletion man/tm_t_events_by_grade.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading