Skip to content

Commit

Permalink
Merge pull request #155 from pharmaverse/enhancement/selection-of-gro…
Browse files Browse the repository at this point in the history
…uping

Enhancement: Automatic selection of grouping vars
  • Loading branch information
js3110 authored Jan 8, 2025
2 parents 411c49c + 93f8a19 commit c55ac67
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
37 changes: 27 additions & 10 deletions inst/shiny/functions/mapping_selectize_inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,33 @@
#' @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
}
# 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
)
}

Expand All @@ -42,13 +63,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)
)
}
8 changes: 4 additions & 4 deletions inst/shiny/modules/column_mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c55ac67

Please sign in to comment.