From fc393c895dba0b2a3645d873669176913c54a714 Mon Sep 17 00:00:00 2001 From: Spinner Date: Tue, 7 Jan 2025 16:47:54 +0100 Subject: [PATCH 1/3] automatic selection of grouping vars --- .../functions/mapping_selectize_inputs.R | 39 ++++++++++++++----- inst/shiny/modules/column_mapping.R | 10 ++--- inst/shiny/server.R | 2 +- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/inst/shiny/functions/mapping_selectize_inputs.R b/inst/shiny/functions/mapping_selectize_inputs.R index b4f67a82..f55d0363 100644 --- a/inst/shiny/functions/mapping_selectize_inputs.R +++ b/inst/shiny/functions/mapping_selectize_inputs.R @@ -13,12 +13,35 @@ #' @return None. This function updates the selectize inputs in the Shiny session. update_selectize_inputs <- function(session, input_ids, column_names, manual_units, desired_order) { + + # Define the desired columns for Grouping_Variables + desired_grouping_columns <- c("TRTA", "TRTAN", "ACTARM", "TRT01A", + "TRT01P", "AGE", "RACE", "SEX", "GROUP") + for (input_id in input_ids) { + # Remove the "select_" prefix to get the actual column name column_name <- sub("select_", "", input_id) - selected_value <- if (column_name %in% column_names) column_name else NULL + # Determine the selected value(s) based on the column name + if (column_name == "Grouping_Variables") { + # Find which desired grouping columns are present + selected_values <- intersect(desired_grouping_columns, column_names) + + # If none are present, set to NULL + if (length(selected_values) == 0) { + selected_values <- NULL + } + } else { + # For other columns, use basic logic + selected_values <- if (column_name %in% column_names) column_name else NULL + } + print(paste("Updating input:", input_id)) + print(paste("Selected values:", paste(selected_values, collapse = ", "))) + # Update the Selectize input with the new choices and selected values updateSelectizeInput( - session, input_id, choices = c("Select Column" = "", column_names), - selected = selected_value + session, + input_id, + choices = c("Select Column" = "", column_names), + selected = selected_values ) } @@ -42,13 +65,9 @@ update_selectize_inputs <- function(session, input_ids, column_names, manual_uni updateSelectizeInput( session, input_id, choices = special_cases[[input_id]], - selected = if (sub("select_", "", input_id) - %in% column_names) sub("select_", "", input_id) else NULL + selected = + if (sub("select_", "", input_id) %in% column_names) + sub("select_", "", input_id) else NULL ) } - - updateSelectizeInput( - session, "select_Grouping_Variables", - choices = setdiff(column_names, desired_order) - ) } diff --git a/inst/shiny/modules/column_mapping.R b/inst/shiny/modules/column_mapping.R index 827f1812..d9ef5930 100644 --- a/inst/shiny/modules/column_mapping.R +++ b/inst/shiny/modules/column_mapping.R @@ -75,7 +75,7 @@ column_mapping_ui <- function(id) { tooltip( selectizeInput( ns("select_Grouping_Variables"), - "Grouping Variables", + "Grouping_Variables", choices = NULL, multiple = TRUE, options = list(placeholder = "Select Column(s)") @@ -243,7 +243,7 @@ column_mapping_server <- function(id, data, manual_units, on_submit) { # Define the required columns and group them into categories column_groups <- list( - "Group Identifiers" = c("STUDYID", "USUBJID", "Grouping Variables"), + "Group Identifiers" = c("STUDYID", "USUBJID", "Grouping_Variables"), "Sample Variables" = c("ANALYTE", "PCSPEC", "ROUTE", "AVAL"), "Dose Variables" = c("DOSNO", "DOSEA", "ADOSEDUR"), "Time Variables" = c("AFRLT", "ARRLT", "NFRLT", "NRRLT"), @@ -299,12 +299,12 @@ column_mapping_server <- function(id, data, manual_units, on_submit) { return() } - # Extract and store the "Grouping Variables" column + # Extract and store the "Grouping_Variables" column grouping_variables(input$select_Grouping_Variables) - # Remove "Grouping Variables" from selected columns to prevent renaming + # Remove "Grouping_Variables" from selected columns to prevent renaming selected_cols[["Group Identifiers"]] <- selected_cols[["Group Identifiers"]][ - names(selected_cols[["Group Identifiers"]]) != "Grouping Variables" + names(selected_cols[["Group Identifiers"]]) != "Grouping_Variables" ] # Rename columns diff --git a/inst/shiny/server.R b/inst/shiny/server.R index d9007009..890208a2 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -7,7 +7,7 @@ function(input, output, session) { data_module <- tab_data_server("data") # Data set for analysis data <- data_module$data - # Grouping Variables + # Grouping_Variables grouping_vars <- data_module$grouping_variables # NCA ---- source(system.file("shiny/tabs/nca.R", package = "aNCA"), local = TRUE) From 0e1d06e2c32f2811b3cbbf35bd71742fb228d196 Mon Sep 17 00:00:00 2001 From: Spinner Date: Tue, 7 Jan 2025 16:50:44 +0100 Subject: [PATCH 2/3] clean labels --- inst/shiny/modules/column_mapping.R | 2 +- inst/shiny/server.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/shiny/modules/column_mapping.R b/inst/shiny/modules/column_mapping.R index d9ef5930..386f06e2 100644 --- a/inst/shiny/modules/column_mapping.R +++ b/inst/shiny/modules/column_mapping.R @@ -75,7 +75,7 @@ column_mapping_ui <- function(id) { tooltip( selectizeInput( ns("select_Grouping_Variables"), - "Grouping_Variables", + "Grouping Variables", choices = NULL, multiple = TRUE, options = list(placeholder = "Select Column(s)") diff --git a/inst/shiny/server.R b/inst/shiny/server.R index 890208a2..d9007009 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -7,7 +7,7 @@ function(input, output, session) { data_module <- tab_data_server("data") # Data set for analysis data <- data_module$data - # Grouping_Variables + # Grouping Variables grouping_vars <- data_module$grouping_variables # NCA ---- source(system.file("shiny/tabs/nca.R", package = "aNCA"), local = TRUE) From 93f8a1954c41dc5fb32e4a6b01ee588730b4f72a Mon Sep 17 00:00:00 2001 From: Spinner Date: Tue, 7 Jan 2025 18:19:23 +0100 Subject: [PATCH 3/3] remove debugging statements --- inst/shiny/functions/mapping_selectize_inputs.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/inst/shiny/functions/mapping_selectize_inputs.R b/inst/shiny/functions/mapping_selectize_inputs.R index f55d0363..ac5c1a01 100644 --- a/inst/shiny/functions/mapping_selectize_inputs.R +++ b/inst/shiny/functions/mapping_selectize_inputs.R @@ -34,8 +34,6 @@ update_selectize_inputs <- function(session, input_ids, column_names, manual_uni # For other columns, use basic logic selected_values <- if (column_name %in% column_names) column_name else NULL } - print(paste("Updating input:", input_id)) - print(paste("Selected values:", paste(selected_values, collapse = ", "))) # Update the Selectize input with the new choices and selected values updateSelectizeInput( session,