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

Enhancement: Automatic selection of grouping vars #155

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
39 changes: 29 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,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 = ", ")))
js3110 marked this conversation as resolved.
Show resolved Hide resolved
# 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 +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)
)
}
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
Loading