Skip to content

Commit

Permalink
Handle delayed choices (#256)
Browse files Browse the repository at this point in the history
Closes #255 

Fixes the modules to get delayed choices:
- [x] tm_g_gh_boxplot
- [x] tm_g_gh_correlationplot
- [x] tm_g_gh_density_distribution_plot
- [x] tm_g_gh_lineplot
- [x] tm_g_gh_scatterplot
- [x] tm_g_gh_spaghettiplot

---------

Signed-off-by: Marcin <[email protected]>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Marcin <[email protected]>
  • Loading branch information
3 people authored Feb 14, 2024
1 parent ac7fec3 commit 7fd5c73
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 61 deletions.
35 changes: 22 additions & 13 deletions R/tm_g_gh_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"
#'
#' # add LLOQ and ULOQ variables
#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB)
#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL")
#' ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM")
#' })
#'
Expand Down Expand Up @@ -210,7 +210,8 @@ tm_g_gh_boxplot <- function(label,
plot_height = plot_height,
plot_width = plot_width,
hline_vars_colors = hline_vars_colors,
hline_vars_labels = hline_vars_labels
hline_vars_labels = hline_vars_labels,
module_args = args
),
ui = ui_g_boxplot,
ui_args = args
Expand Down Expand Up @@ -251,16 +252,7 @@ ui_g_boxplot <- function(id, ...) {
selected = a$trt_group$selected,
multiple = FALSE
),
templ_ui_params_vars(
ns,
xparam_choices = a$param$choices,
xparam_selected = a$param$selected,
xparam_label = "Select a Biomarker",
xchoices = a$xaxis_var$choices,
xselected = a$xaxis_var$selected,
ychoices = a$yaxis_var$choices,
yselected = a$yaxis_var$selected
),
uiOutput(ns("axis_selections")),
teal.widgets::optionalSelectInput(
ns("facet_var"),
label = "Facet by",
Expand Down Expand Up @@ -324,13 +316,30 @@ srv_g_boxplot <- function(id,
plot_height,
plot_width,
hline_vars_colors,
hline_vars_labels) {
hline_vars_labels,
module_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
output$axis_selections <- renderUI({
env <- shiny::isolate(as.list(data()@env))
resolved_x <- teal.transform::resolve_delayed(module_args$xaxis_var, env)
resolved_y <- teal.transform::resolve_delayed(module_args$yaxis_var, env)
resolved_param <- teal.transform::resolve_delayed(module_args$param, env)
templ_ui_params_vars(
session$ns,
xparam_choices = resolved_param$choices,
xparam_selected = resolved_param$selected,
xparam_label = module_args$"Select a Biomarker",
xchoices = resolved_x$choices,
xselected = resolved_x$selected,
ychoices = resolved_y$choices,
yselected = resolved_y$selected
)
})
# reused in all modules
anl_q_output <- constr_anl_q(
session, input, data, dataname,
Expand Down
35 changes: 25 additions & 10 deletions R/tm_g_gh_correlationplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
#' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit"
#'
#' # add LLOQ and ULOQ variables
#' ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB)
#' ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL")
#' ADLB <- dplyr::left_join(ADLB, ADLB_LOQS, by = "PARAM")
#' })
#'
Expand Down Expand Up @@ -259,7 +259,8 @@ tm_g_gh_correlationplot <- function(label,
hline_vars_colors = hline_vars_colors,
hline_vars_labels = hline_vars_labels,
vline_vars_colors = vline_vars_colors,
vline_vars_labels = vline_vars_labels
vline_vars_labels = vline_vars_labels,
module_args = args
),
ui = ui_g_correlationplot,
ui_args = args
Expand All @@ -284,13 +285,7 @@ ui_g_correlationplot <- function(id, ...) {
selected = a$trt_group$selected,
multiple = FALSE
),
templ_ui_params_vars(
ns,
xparam_choices = a$xaxis_param$choices, xparam_selected = a$xaxis_param$selected,
xchoices = a$xaxis_var$choices, xselected = a$xaxis_var$selected,
yparam_choices = a$yaxis_param$choices, yparam_selected = a$yaxis_param$selected,
ychoices = a$yaxis_var$choices, yselected = a$yaxis_var$selected
),
uiOutput(ns("axis_selections")),
templ_ui_constraint(ns, "X-Axis Data Constraint"), # required by constr_anl_q
if (length(a$hline_vars) > 0) {
teal.widgets::optionalSelectInput(
Expand Down Expand Up @@ -375,13 +370,33 @@ srv_g_correlationplot <- function(id,
hline_vars_colors,
hline_vars_labels,
vline_vars_colors,
vline_vars_labels) {
vline_vars_labels,
module_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
output$axis_selections <- renderUI({
env <- shiny::isolate(as.list(data()@env))
resolved_x_param <- teal.transform::resolve_delayed(module_args$xaxis_param, env)
resolved_x_var <- teal.transform::resolve_delayed(module_args$xaxis_var, env)
resolved_y_param <- teal.transform::resolve_delayed(module_args$yaxis_param, env)
resolved_y_var <- teal.transform::resolve_delayed(module_args$yaxis_var, env)
templ_ui_params_vars(
session$ns,
xparam_choices = resolved_x_param$choices,
xparam_selected = resolved_x_param$selected,
xchoices = resolved_x_var$choices,
xselected = resolved_x_var$selected,
yparam_choices = resolved_y_param$choices,
yparam_selected = resolved_y_param$selected,
ychoices = resolved_y_var$choices,
yselected = resolved_y_var$selected
)
})

iv_r <- reactive({
iv <- shinyvalidate::InputValidator$new()

Expand Down
26 changes: 19 additions & 7 deletions R/tm_g_gh_density_distribution_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ tm_g_gh_density_distribution_plot <- function(label, # nolint
color_manual = color_manual,
color_comb = color_comb,
plot_height = plot_height,
plot_width = plot_width
plot_width = plot_width,
module_args = args
),
ui = ui_g_density_distribution_plot,
ui_args = args
Expand Down Expand Up @@ -201,11 +202,7 @@ ui_g_density_distribution_plot <- function(id, ...) {
selected = a$trt_group$selected,
multiple = FALSE
),
templ_ui_params_vars(
ns,
xparam_choices = a$param$choices, xparam_selected = a$param$selected, xparam_label = "Select a Biomarker",
xchoices = a$xaxis_var$choices, xselected = a$xaxis_var$selected
),
uiOutput(ns("axis_selections")),
templ_ui_constraint(ns, label = "Data Constraint"),
ui_arbitrary_lines(id = ns("hline_arb"), a$hline_arb, a$hline_arb_label, a$hline_arb_color),
teal.widgets::panel_group(
Expand Down Expand Up @@ -263,13 +260,28 @@ srv_g_density_distribution_plot <- function(id, # nolint
color_manual,
color_comb,
plot_height,
plot_width) {
plot_width,
module_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
output$axis_selections <- renderUI({
env <- shiny::isolate(as.list(data()@env))
resolved_x <- teal.transform::resolve_delayed(module_args$xaxis_var, env)
resolved_param <- teal.transform::resolve_delayed(module_args$param, env)
templ_ui_params_vars(
session$ns,
xparam_choices = resolved_param$choices,
xparam_selected = resolved_param$selected,
xparam_label = "Select a Biomarker",
xchoices = resolved_x$choices,
xselected = resolved_x$selected
)
})

anl_q_output <- constr_anl_q(
session, input, data, dataname,
param_id = "xaxis_param", param_var = param_var, trt_group = input$trt_group, min_rows = 2
Expand Down
33 changes: 24 additions & 9 deletions R/tm_g_gh_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ tm_g_gh_lineplot <- function(label,
xtick = xtick,
xlabel = xlabel,
plot_height = plot_height,
plot_width = plot_width
plot_width = plot_width,
module_args = args
),
ui = ui_lineplot,
ui_args = args,
Expand Down Expand Up @@ -226,13 +227,7 @@ ui_lineplot <- function(id, ...) {
selected = a$trt_group$selected,
multiple = FALSE
),
templ_ui_params_vars(
ns,
# xparam and yparam are identical, so we only show the user one
xparam_choices = a$param$choices, xparam_selected = a$param$selected, xparam_label = "Select a Biomarker",
xchoices = a$xaxis_var$choices, xselected = a$xaxis_var$selected,
ychoices = a$yaxis_var$choices, yselected = a$yaxis_var$selected
),
uiOutput(ns("axis_selections")),
uiOutput(ns("shape_ui")),
radioButtons(ns("stat"), "Select a Statistic:", c("mean", "median"), a$stat),
checkboxInput(ns("include_stat"), "Include Statistic Table", value = TRUE),
Expand Down Expand Up @@ -328,14 +323,34 @@ srv_lineplot <- function(id,
xtick,
xlabel,
plot_height,
plot_width) {
plot_width,
module_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
ns <- session$ns

output$axis_selections <- renderUI({
env <- shiny::isolate(as.list(data()@env))
resolved_x <- teal.transform::resolve_delayed(module_args$xaxis_var, env)
resolved_y <- teal.transform::resolve_delayed(module_args$yaxis_var, env)
resolved_param <- teal.transform::resolve_delayed(module_args$param, env)
templ_ui_params_vars(
ns,
# xparam and yparam are identical, so we only show the user one
xparam_choices = resolved_param$choices,
xparam_selected = resolved_param$selected,
xparam_label = "Select a Biomarker",
xchoices = resolved_x$choices,
xselected = resolved_x$selected,
ychoices = resolved_y$choices,
yselected = resolved_y$selected
)
})

output$shape_ui <- renderUI({
if (!is.null(shape_choices)) {
if (methods::is(shape_choices, "choices_selected")) {
Expand Down
32 changes: 23 additions & 9 deletions R/tm_g_gh_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ tm_g_gh_scatterplot <- function(label,
color_manual = color_manual,
shape_manual = shape_manual,
plot_height = plot_height,
plot_width = plot_width
plot_width = plot_width,
module_args = args
),
ui = ui_g_scatterplot,
ui_args = args
Expand All @@ -200,13 +201,7 @@ ui_g_scatterplot <- function(id, ...) {
selected = a$trt_group$selected,
multiple = FALSE
),
templ_ui_params_vars(
ns,
# xparam and yparam are identical, so we only show the user one
xparam_choices = a$param$choices, xparam_selected = a$param$selected, xparam_label = "Select a Biomarker",
xchoices = a$xaxis_var$choices, xselected = a$xaxis_var$selected,
ychoices = a$yaxis_var$choices, yselected = a$yaxis_var$selected
),
uiOutput(ns("axis_selections")),
templ_ui_constraint(ns), # required by constr_anl_q
teal.widgets::panel_group(
teal.widgets::panel_item(
Expand Down Expand Up @@ -263,13 +258,32 @@ srv_g_scatterplot <- function(id,
color_manual,
shape_manual,
plot_height,
plot_width) {
plot_width,
module_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
output$axis_selections <- renderUI({
env <- shiny::isolate(as.list(data()@env))
resolved_x <- teal.transform::resolve_delayed(module_args$xaxis_var, env)
resolved_y <- teal.transform::resolve_delayed(module_args$yaxis_var, env)
resolved_param <- teal.transform::resolve_delayed(module_args$param, env)
templ_ui_params_vars(
session$ns,
# xparam and yparam are identical, so we only show the user one
xparam_choices = resolved_param$choices,
xparam_selected = resolved_param$selected,
xparam_label = "Select a Biomarker",
xchoices = resolved_x$choices,
xselected = resolved_x$selected,
ychoices = resolved_y$choices,
yselected = resolved_y$selected
)
})

# reused in all modules
anl_q_output <- constr_anl_q(
session, input, data, dataname,
Expand Down
34 changes: 24 additions & 10 deletions R/tm_g_gh_spaghettiplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"
#'
#' # add LLOQ and ULOQ variables
#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB)
#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL")
#' ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM")
#' })
#'
Expand Down Expand Up @@ -222,7 +222,8 @@ tm_g_gh_spaghettiplot <- function(label,
plot_height = plot_height,
plot_width = plot_width,
hline_vars_colors = hline_vars_colors,
hline_vars_labels = hline_vars_labels
hline_vars_labels = hline_vars_labels,
module_args = args
),
ui = g_ui_spaghettiplot,
ui_args = args,
Expand Down Expand Up @@ -250,13 +251,7 @@ g_ui_spaghettiplot <- function(id, ...) {
selected = a$trt_group$selected,
multiple = FALSE
),
templ_ui_params_vars(
ns,
# xparam and yparam are identical, so we only show the user one
xparam_choices = a$param$choices, xparam_selected = a$param$selected, xparam_label = "Select a Biomarker",
xchoices = a$xaxis_var$choices, xselected = a$xaxis_var$selected,
ychoices = a$yaxis_var$choices, yselected = a$yaxis_var$selected
),
uiOutput(ns("axis_selections")),
radioButtons(
ns("group_stats"),
"Group Statistics",
Expand Down Expand Up @@ -339,13 +334,32 @@ srv_g_spaghettiplot <- function(id,
plot_height,
plot_width,
hline_vars_colors,
hline_vars_labels) {
hline_vars_labels,
module_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
output$axis_selections <- renderUI({
env <- shiny::isolate(as.list(data()@env))
resolved_x <- teal.transform::resolve_delayed(module_args$xaxis_var, env)
resolved_y <- teal.transform::resolve_delayed(module_args$yaxis_var, env)
resolved_param <- teal.transform::resolve_delayed(module_args$param, env)
templ_ui_params_vars(
session$ns,
# xparam and yparam are identical, so we only show the user one
xparam_choices = resolved_param$choices,
xparam_selected = resolved_param$selected,
xparam_label = "Select a Biomarker",
xchoices = resolved_x$choices,
xselected = resolved_x$selected,
ychoices = resolved_y$choices,
yselected = resolved_y$selected
)
})

# reused in all modules
anl_q_output <- constr_anl_q(
session, input, data, dataname,
Expand Down
2 changes: 1 addition & 1 deletion man/tm_g_gh_boxplot.Rd

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

2 changes: 1 addition & 1 deletion man/tm_g_gh_correlationplot.Rd

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

Loading

0 comments on commit 7fd5c73

Please sign in to comment.