From 343b5f901f86079a77175ac5948196996c146719 Mon Sep 17 00:00:00 2001 From: m7pr Date: Fri, 4 Oct 2024 12:59:01 +0200 Subject: [PATCH 1/2] allow facet_var to be a delayed variables_choice for tm_g_gh_boxplot --- R/tm_g_gh_boxplot.R | 28 +++++++++++++--------------- R/utils-templ_ui.r | 13 +++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/R/tm_g_gh_boxplot.R b/R/tm_g_gh_boxplot.R index a8dc415a..f28c1743 100644 --- a/R/tm_g_gh_boxplot.R +++ b/R/tm_g_gh_boxplot.R @@ -207,7 +207,6 @@ tm_g_gh_boxplot <- function(label, dataname = dataname, param_var = param_var, trt_group = trt_group, - facet_var = facet_var, color_manual = color_manual, shape_manual = shape_manual, plot_height = plot_height, @@ -256,13 +255,6 @@ ui_g_boxplot <- function(id, ...) { multiple = FALSE ), uiOutput(ns("axis_selections")), - teal.widgets::optionalSelectInput( - ns("facet_var"), - label = "Facet by", - choices = get_choices(a$facet_var$choices), - selected = a$facet_var$selected, - multiple = FALSE - ), templ_ui_constraint(ns, label = "Data Constraint"), # required by constr_anl_q if (length(a$hline_vars) > 0) { teal.widgets::optionalSelectInput( @@ -312,7 +304,6 @@ srv_g_boxplot <- function(id, dataname, param_var, trt_group, - facet_var, color_manual, shape_manual, plot_height, @@ -331,6 +322,8 @@ srv_g_boxplot <- function(id, 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) + resolved_facet_var <- teal.transform::resolve_delayed(module_args$facet_var, env) + templ_ui_params_vars( session$ns, xparam_choices = resolved_param$choices, @@ -338,8 +331,12 @@ srv_g_boxplot <- function(id, xparam_label = module_args$"Select a Biomarker", xchoices = resolved_x$choices, xselected = resolved_x$selected, + ychoices = resolved_y$choices, - yselected = resolved_y$selected + yselected = resolved_y$selected, + + facet_choices = resolved_facet_var$choices, + facet_selected = resolved_facet_var$selected ) }) # reused in all modules @@ -477,6 +474,7 @@ srv_g_boxplot <- function(id, xaxis_var <- input$yaxis_var # nolint font_size <- input$font_size trt_group <- input$trt_group + facet_var <- input$facet_var anl_q()$qenv %>% teal.code::eval_code( code = bquote({ @@ -486,7 +484,7 @@ srv_g_boxplot <- function(id, param_var = .(param_var), param = .(param), xaxis_var = .(xaxis_var), - facet_var = .(input$facet_var) + facet_var = .(facet_var) ) }) ) @@ -511,8 +509,8 @@ srv_g_boxplot <- function(id, numeric_cols <- setdiff(names(dplyr::select_if(tbl, is.numeric)), "n") DT::datatable(tbl, - rownames = FALSE, options = list(scrollX = TRUE), - callback = DT::JS("$.fn.dataTable.ext.errMode = 'none';") + rownames = FALSE, options = list(scrollX = TRUE), + callback = DT::JS("$.fn.dataTable.ext.errMode = 'none';") ) %>% DT::formatRound(numeric_cols, 4) }) @@ -581,8 +579,8 @@ srv_g_boxplot <- function(id, numeric_cols <- names(dplyr::select_if(df, is.numeric)) DT::datatable(df, - rownames = FALSE, options = list(scrollX = TRUE), - callback = DT::JS("$.fn.dataTable.ext.errMode = 'none';") + rownames = FALSE, options = list(scrollX = TRUE), + callback = DT::JS("$.fn.dataTable.ext.errMode = 'none';") ) %>% DT::formatRound(numeric_cols, 4) }) diff --git a/R/utils-templ_ui.r b/R/utils-templ_ui.r index 6d3ca49a..a0897e99 100644 --- a/R/utils-templ_ui.r +++ b/R/utils-templ_ui.r @@ -27,6 +27,10 @@ templ_ui_params_vars <- function(ns, ychoices = NULL, yselected = NULL, yvar_label = NULL, # variable, e.g. AVAL + # facet_var + facet_choices = NULL, + facet_selected = NULL, + multiple = FALSE) { if (is.null(xparam_choices) && !is.null(xchoices) && !is.null(yparam_choices)) { # otherwise, xchoices will appear first without any biomarker to select and this looks odd in the UI @@ -69,6 +73,15 @@ templ_ui_params_vars <- function(ns, ychoices, yselected, multiple = multiple ) + }, + if (!is.null(facet_choices)) { + teal.widgets::optionalSelectInput( + ns("facet_var"), + label = "Facet by", + choices = facet_choices, + selected = facet_selected, + multiple = FALSE + ) } ) } From defa8149ffb90afd5f3738638e26e7ce6a1324af Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:06:38 +0000 Subject: [PATCH 2/2] [skip style] [skip vbump] Restyle files --- R/tm_g_gh_boxplot.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/tm_g_gh_boxplot.R b/R/tm_g_gh_boxplot.R index 3da47bb2..da34f7a7 100644 --- a/R/tm_g_gh_boxplot.R +++ b/R/tm_g_gh_boxplot.R @@ -331,10 +331,8 @@ srv_g_boxplot <- function(id, xparam_label = module_args$"Select a Biomarker", xchoices = resolved_x$choices, xselected = resolved_x$selected, - ychoices = resolved_y$choices, yselected = resolved_y$selected, - facet_choices = resolved_facet_var$choices, facet_selected = resolved_facet_var$selected )