diff --git a/R/label_operators.R b/R/label_operators.R index 23eb14bd..251e85dd 100644 --- a/R/label_operators.R +++ b/R/label_operators.R @@ -117,14 +117,14 @@ set_empty_label <- function(x) { } #' Get the Label of a Heading -#' +#' #' This function retrieves the label of a heading from a labels file. -#' +#' #' @param variable The variable for which the label is to be retrieved. -#' +#' #' @return The label of the heading if it exists in the labels file, #' otherwise "No label available". -#' +#' #' @examples #' \dontrun{ #' # Example usage: @@ -135,7 +135,7 @@ set_empty_label <- function(x) { #' get_label("USUBJID") # Returns "Unique Subject Identifier" #' get_label("AGE") # Returns "No label available" #' } -#' +#' #' @export get_label <- function(variable) { label <- unique(labels_file$Label[labels_file$Variable == variable]) @@ -143,4 +143,4 @@ get_label <- function(variable) { return("No label available") } return(label) -} \ No newline at end of file +} diff --git a/inst/shiny/modules/column_mapping.R b/inst/shiny/modules/column_mapping.R index 1ac14607..c50f4ba1 100644 --- a/inst/shiny/modules/column_mapping.R +++ b/inst/shiny/modules/column_mapping.R @@ -42,72 +42,86 @@ column_mapping_ui <- function(id) { ns <- NS(id) - + tagList( h3("Data Mapping"), p( "The following columns are required for data analysis. Please ensure each of these columns", " has been assigned a corresponding column from your dataset" ), - h4("Group Identifiers"), - # Adjusted layout using CSS flexbox tagList( tags$style( type = "text/css", - ".shiny-input-container { margin-bottom: 0px; }" + " + h4 { + margin-bottom: -40px; /* Reduce space below h4 headings */ + } + .fluidRow { + margin-top: -5px; /* Reduce space above rows */ + } + .shiny-input-container {margin-bottom: 0px; }" ), + h4("Group Identifiers"), fluidRow( column( - 12, + 8, div( - style = "display: flex; align-items: center; margin-bottom: -5px; margin-top: -15px;", + style = "display: flex; align-items: center; margin-bottom: -45px;", tooltip( selectizeInput( ns("select_STUDYID"), "", choices = NULL, options = list(placeholder = "Select Column"), - width = '50%' + width = "25%" ), - "Select Study ID Column" + "Select Corresponding Column, in character format." ), div( style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("STUDYID:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_STUDYID")), style = "color: grey;") + span("STUDYID:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_STUDYID")), + style = "color: grey;") ) ) ) ), fluidRow( column( - 12, + 8, div( - style = "display: flex; align-items: center; margin-bottom: -5px;", + style = "display: flex; align-items: center; margin-bottom: -45px;", tooltip( selectizeInput( ns("select_USUBJID"), "", choices = NULL, options = list(placeholder = "Select Column"), - width = '50%' + width = "25%" ), - "Unique subject identifier." + "Character or Numeric format" ), div( style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", span("USUBJID:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_USUBJID")), style = "color: grey;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_USUBJID")), + style = "color: grey;") ) ) ) ), fluidRow( column( - 12, + 8, div( - style = "display: flex; align-items: center; margin-bottom: -5px;", + style = "display: flex; align-items: center; margin-bottom: -15px;", tooltip( selectizeInput( ns("select_Grouping_Variables"), @@ -115,329 +129,403 @@ column_mapping_ui <- function(id) { choices = NULL, multiple = TRUE, options = list(placeholder = "Select Column(s)"), - width = '50%' + width = "25%" ), - "Select the additional column(s) that will be used to group the data\nfor tables, listings and graphs. E.g. Treatment Arm, Age, Sex, Race" + "Select the additional column(s) that will be used to group the data\n + for tables, listings and graphs. E.g. Treatment Arm, Age, Sex, Race" ), div( style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", span("Additional Grouping Variables", style = "color: black; font-size: normal;") - ) + ), ) ) - ) - ), - - fluidRow( + ), h4("Sample Variables"), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_ANALYTE"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Analyte" - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("ANALYTE:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_ANALYTE")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_ANALYTE"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Analyte" + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("ANALYTE:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_ANALYTE")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_PCSPEC"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Matrix" - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("PCSPEC:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_PCSPEC")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_PCSPEC"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Matrix" + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("PCSPEC:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_PCSPEC")), + style = "color: grey;") + ) + ) + ) + ), + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -15px;", + tooltip( + selectizeInput( + ns("select_AVAL"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Analysis value in numeric format." + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("AVAL:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_AVAL")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_AVAL"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Analysis value in numeric format." - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("AVAL:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_AVAL")), - style = "color: grey;") - ) - ) - ) - ), - - fluidRow( h4("Dose Variables"), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_DOSNO"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Numeric format." - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("DOSNO:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_DOSNO")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_DOSNO"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Numeric format." + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("DOSNO:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_DOSNO")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_ROUTE"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Route of administration, stating either 'intravascular' or 'extravascular'." - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("ROUTE:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_ROUTE")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_ROUTE"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Route of administration, stating either 'intravascular' or 'extravascular'." + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("ROUTE:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_ROUTE")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_DOSEA"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Actual Dose amount in numeric format." - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("DOSEA:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_DOSEA")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_DOSEA"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Actual Dose amount in numeric format." + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("DOSEA:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_DOSEA")), + style = "color: grey;") + ) + ) + ) + ), + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -15px;", + tooltip( + selectizeInput( + ns("select_ADOSEDUR"), + "", + choices = c("Select Column" = "", "NA"), + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Duration of dose administration. + Only required for infusion studies,\notherwise select NA" + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("ADOSEDUR:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_ADOSEDUR")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_ADOSEDUR"), - "", - choices = c("Select Column" = "", "NA"), - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Duration of dose administration. Only required for infusion studies,\notherwise select NA" - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("ADOSEDUR:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_ADOSEDUR")), - style = "color: grey;") - ) - ) - ) - ), - - fluidRow( h4("Time Variables"), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_AFRLT"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Numeric format" - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("AFRLT:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_AFRLT")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_AFRLT"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Numeric format" + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("AFRLT:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_AFRLT")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_ARRLT"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Numeric format" - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("ARRLT:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_ARRLT")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_ARRLT"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Numeric format" + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("ARRLT:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_ARRLT")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_NFRLT"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Numeric format" - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("NFRLT:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_NFRLT")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_NFRLT"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Numeric format" + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("NFRLT:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_NFRLT")), + style = "color: grey;") + ) + ) + ) + ), + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -15px;", + tooltip( + selectizeInput( + ns("select_NRRLT"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Numeric format" + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("NRRLT:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_NRRLT")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_NRRLT"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Numeric format" - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("NRRLT:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_NRRLT")), - style = "color: grey;") - ) - ) - ) - ), - - fluidRow( h4("Unit Variables"), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_AVALU"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Unit of analysis value." - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("AVALU:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_AVALU")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_AVALU"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Unit of analysis value." + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("AVALU:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_AVALU")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_DOSEU"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Unit of dose amount." - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("DOSEU:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_DOSEU")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -45px;", + tooltip( + selectizeInput( + ns("select_DOSEU"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Unit of dose amount." + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("DOSEU:", style = "color: black; font-size: normal;") + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_DOSEU")), + style = "color: grey;") + ) + ) + ) ), - column(12, - div( - style = "display: flex; align-items: center; margin-bottom: -5px;", - tooltip( - selectizeInput( - ns("select_RRLTU"), - "", - choices = NULL, - options = list(placeholder = "Select Column"), - width = '50%' - ), - "Unit of time." - ), - div( - style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", - span("RRLTU:", style = "color: black; font-size: normal;"), - span(textOutput(ns("label_RRLTU")), - style = "color: grey;") - ) - ) + fluidRow( + column( + 8, + div( + style = "display: flex; align-items: center; margin-bottom: -15px;", + tooltip( + selectizeInput( + ns("select_RRLTU"), + "", + choices = NULL, + options = list(placeholder = "Select Column"), + width = "25%" + ), + "Unit of time." + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span("RRLTU:", style = "color: black; font-size: normal;"), + ), + div( + style = "margin-left: 10px; margin-top: 20px; margin-bottom: 0px;", + span(textOutput(ns("label_RRLTU")), + style = "color: grey;") + ) + ) + ) ) ), - + input_task_button(ns("submit_columns"), "Submit Mapping") ) } @@ -454,25 +542,7 @@ column_mapping_server <- function(id, data, manual_units, on_submit) { "Time Variables" = c("AFRLT", "ARRLT", "NFRLT", "NRRLT"), "Unit Variables" = c("AVALU", "DOSEU", "RRLTU") ) - - # Define outputs for each label - output$label_STUDYID <- renderText({ get_label("STUDYID") }) - output$label_USUBJID <- renderText({ get_label("USUBJID") }) - output$label_ANALYTE <- renderText({ get_label("ANALYTE") }) - output$label_PCSPEC <- renderText({ get_label("PCSPEC") }) - output$label_AVAL <- renderText({ get_label("AVAL") }) - output$label_DOSNO <- renderText({ get_label("DOSNO") }) - output$label_ROUTE <- renderText({ get_label("ROUTE") }) - output$label_DOSEA <- renderText({ get_label("DOSEA") }) - output$label_ADOSEDUR <- renderText({ get_label("ADOSEDUR") }) - output$label_AFRLT <- renderText({ get_label("AFRLT") }) - output$label_ARRLT <- renderText({ get_label("ARRLT") }) - output$label_NFRLT <- renderText({ get_label("NFRLT") }) - output$label_NRRLT <- renderText({ get_label("NRRLT") }) - output$label_AVALU <- renderText({ get_label("AVALU") }) - output$label_DOSEU <- renderText({ get_label("DOSEU") }) - output$label_RRLTU <- renderText({ get_label("RRLTU") }) - + # Derive input IDs from column_groups input_ids <- unlist(lapply(column_groups, function(cols) { @@ -483,7 +553,19 @@ column_mapping_server <- function(id, data, manual_units, on_submit) { desired_order <- c("STUDYID", "USUBJID", "ANALYTE", "PCSPEC", "AVAL", "AVALU", "AFRLT", "ARRLT", "NRRLT", "NFRLT", "RRLTU", - "ROUTE", "DOSEA", "DOSEU", "DOSNO") + "ROUTE", "DOSEA", "DOSEU", "DOSNO", + "ADOSEDUR") + + # Loop through each label and create the renderText outputs + for (label in desired_order) { + local({ + current_label <- label + output_name <- paste0("label_", current_label) + output[[output_name]] <- renderText({ + get_label(current_label) + }) + }) + } # Populate the static inputs with column names observeEvent(data(), {