From bc66f5c3f442610c8b1ad509f07eecd784c01067 Mon Sep 17 00:00:00 2001 From: Spinner Date: Mon, 20 Jan 2025 15:19:03 +0100 Subject: [PATCH] clean and lint --- R/format_data.R | 2 +- R/general_lineplot.R | 7 ++++++- R/lambda_slope_plot.R | 5 +++-- inst/shiny/modules/slope_selector.R | 10 ++++++++-- inst/shiny/modules/tab_visuals.R | 21 ++++++++++++--------- inst/shiny/tabs/nca.R | 8 +++++--- inst/shiny/ui.R | 16 +++++++++------- 7 files changed, 44 insertions(+), 25 deletions(-) diff --git a/R/format_data.R b/R/format_data.R index 43144da..79265c0 100644 --- a/R/format_data.R +++ b/R/format_data.R @@ -97,7 +97,7 @@ format_pkncadose_data <- function(pkncaconc_data, slice(1) %>% ungroup() %>% arrange(!!!syms(group_columns)) - + } #' Create Dose Intervals Dataset diff --git a/R/general_lineplot.R b/R/general_lineplot.R index 29dcfe4..2ad421e 100644 --- a/R/general_lineplot.R +++ b/R/general_lineplot.R @@ -52,7 +52,8 @@ #' @importFrom tern g_ipp #' @export general_lineplot <- function( - data, selected_analytes, selected_pcspec, selected_usubjids, colorby_var, time_scale, yaxis_scale, cycle = NULL + data, selected_analytes, selected_pcspec, selected_usubjids, + colorby_var, time_scale, yaxis_scale, cycle = NULL ) { # Check if the data is empty @@ -75,6 +76,10 @@ general_lineplot <- function( DOSEA = factor(DOSEA), id_var = interaction(!!!syms(colorby_var), sep = ", ") ) + # Check if the data is empty + if (nrow(preprocessed_data) == 0) { + return(ggplot() + ggtitle("No data available for selected parameters")) + } # If there are predose records duplicate them in the previous line so they are considered if ("ARRLT" %in% names(preprocessed_data) && diff --git a/R/lambda_slope_plot.R b/R/lambda_slope_plot.R index 8aa9e8e..3b628f5 100644 --- a/R/lambda_slope_plot.R +++ b/R/lambda_slope_plot.R @@ -63,7 +63,8 @@ lambda_slope_plot <- function( # Obtain all information relevant regarding lambda calculation lambda_res <- res_pknca_df %>% - filter(DOSNO == dosno, USUBJID == usubjid, ANALYTE == analyte, PCSPEC == pcspec, type_interval == "main") %>% + filter(DOSNO == dosno, USUBJID == usubjid, ANALYTE == analyte, + PCSPEC == pcspec, type_interval == "main") %>% arrange(USUBJID, DOSNO, ANALYTE, PCSPEC, start, desc(end)) %>% filter(!duplicated(paste0(USUBJID, DOSNO, PCSPEC, ANALYTE, PPTESTCD))) @@ -236,7 +237,7 @@ lambda_slope_plot <- function( pl <- pl %>% # Make this trace the only one add_trace( - data = plot_data %>% filter(DOSNO == dosno, USUBJID == usubjid, + data = plot_data %>% filter(DOSNO == dosno, USUBJID == usubjid, ANALYTE == analyte, PCSPEC == pcspec), x = ~TIME, y = ~log10(AVAL), customdata = ~paste0(USUBJID, "_", DOSNO, "_", IX), diff --git a/inst/shiny/modules/slope_selector.R b/inst/shiny/modules/slope_selector.R index 8b27608..9b74cb5 100644 --- a/inst/shiny/modules/slope_selector.R +++ b/inst/shiny/modules/slope_selector.R @@ -95,7 +95,9 @@ slope_selector_ui <- function(id) { .SLOPE_SELECTOR_COLUMNS <- c("TYPE", "PATIENT", "ANALYTE", "PCSPEC", "PROFILE", "IXrange", "REASON") slope_selector_server <- function( - id, mydata, res_nca, profiles_per_patient, cycle_nca, analyte_nca, pcspec_nca, pk_nca_trigger, settings_upload + id, mydata, res_nca, profiles_per_patient, + cycle_nca, analyte_nca, pcspec_nca, + pk_nca_trigger, settings_upload ) { moduleServer(id, function(input, output, session) { log_trace("{id}: Attaching server") @@ -402,7 +404,11 @@ slope_selector_server <- function( shiny::debounce(750) # Define the click events for the point exclusion and selection in the slope plots - last_click_data <- reactiveValues(patient = "", profile = "", analyte = "", pcspec = "", idx_pnt = "") + last_click_data <- reactiveValues( + patient = "", profile = "", + analyte = "", pcspec = "", + idx_pnt = "" + ) observeEvent(event_data("plotly_click", priority = "event"), { # Store the information of the last click event # click_data <- event_data("plotly_click") diff --git a/inst/shiny/modules/tab_visuals.R b/inst/shiny/modules/tab_visuals.R index a163de5..e555cca 100644 --- a/inst/shiny/modules/tab_visuals.R +++ b/inst/shiny/modules/tab_visuals.R @@ -128,7 +128,7 @@ tab_visuals_ui <- function(id) { orderInput( ns("summary_groupby"), "..to hierarchically group by (order matters!):", - items = c( "ANALYTE", "PCSPEC", "DOSNO"), + items = c("ANALYTE", "PCSPEC", "DOSNO"), width = shiny::validateCssUnit("100%"), connect = ns("summary_groupby_source"), placeholder = "Drag items here to group hierarchically..." @@ -223,13 +223,14 @@ tab_visuals_server <- function(id, data, grouping_vars, res_nca) { param_choices_pcspec <- data() %>% pull(PCSPEC) %>% unique() - + updatePickerInput( session, "generalplot_pcspec", choices = param_choices_pcspec, + selected = param_choices_pcspec[1] ) - + # Update the usubjid picker input param_choices_usubjid <- data() %>% pull(USUBJID) %>% @@ -244,7 +245,7 @@ tab_visuals_server <- function(id, data, grouping_vars, res_nca) { # Update the colorby picker input param_choices_colorby <- sort( - c("STUDYID", "PCSPEC", "ANALYTE", "DOSEA", "DOSNO", "USUBJID", grouping_vars()) + c("STUDYID", "PCSPEC", "ANALYTE", "DOSEA", "DOSNO", "USUBJID", grouping_vars()) ) updatePickerInput( @@ -262,7 +263,8 @@ tab_visuals_server <- function(id, data, grouping_vars, res_nca) { updateSelectInput( session, "analyte_mean", - choices = sort(analyte_choices) + choices = sort(analyte_choices), + selected = analyte_choices[1] ) # Update the studyidmean select input @@ -275,20 +277,21 @@ tab_visuals_server <- function(id, data, grouping_vars, res_nca) { "studyid_mean", choices = sort(studyid_choices) ) - + # Update pcspec mean choices pcspec_choices <- data() %>% pull(PCSPEC) %>% unique() - + updateSelectInput( session, "pcspec_mean", - choices = sort(pcspec_choices) + choices = sort(pcspec_choices), + selected = pcspec_choices[1] ) # Update the selectidvar select input - idvar_choices <- c("ANALYTE","PCSPEC", "DOSEA", grouping_vars()) + idvar_choices <- c("ANALYTE", "PCSPEC", "DOSEA", grouping_vars()) updateSelectInput( session, diff --git a/inst/shiny/tabs/nca.R b/inst/shiny/tabs/nca.R index 0d1a522..d5c6804 100644 --- a/inst/shiny/tabs/nca.R +++ b/inst/shiny/tabs/nca.R @@ -19,7 +19,8 @@ observeEvent(data(), { session, inputId = "select_analyte", label = "Choose the Analyte(s) :", - choices = unique(data()$ANALYTE) + choices = unique(data()$ANALYTE), + selected = unique(data()$ANALYTE)[1] ) }) @@ -28,7 +29,8 @@ observeEvent(data(), { session, inputId = "select_pcspec", label = "Choose the Specimen Type(s) :", - choices = unique(data()$PCSPEC) + choices = unique(data()$PCSPEC), + selected = unique(data()$PCSPEC)[1] ) }) @@ -481,7 +483,7 @@ res_nca <- eventReactive(pk_nca_trigger(), { myres$result <- myres$result %>% inner_join(select(mydata()$dose$data, -exclude)) %>% mutate(start = start - !!sym(mydata()$dose$columns$time), - end = end - !!sym(mydata()$dose$columns$time)) %>% + end = end - !!sym(mydata()$dose$columns$time)) %>% select(names(myres$result)) # Return the result diff --git a/inst/shiny/ui.R b/inst/shiny/ui.R index 878de5a..ffe4cb4 100644 --- a/inst/shiny/ui.R +++ b/inst/shiny/ui.R @@ -51,20 +51,22 @@ fluidPage( # Selection of analyte selectInput( "select_analyte", - "Choose the Analyte :", - choices = NULL, - multiple = TRUE), + "Choose the Analyte(s) :", + choices = c("Please specify ANALYTE" = ""), + multiple = TRUE + ), # Selection of matrix selectInput( "select_pcspec", - "Choose the Matrix:", - choices = NULL, - multiple = TRUE), + "Choose the Specimen Type(s):", + choices = c("Please specify PCSPEC" = ""), + multiple = TRUE + ), selectInput( "select_dosno", "Choose the Dose Number:", multiple = TRUE, - choices = c("Please specify ANALYTE in Data Selection" = "") + choices = c("Please specify ANALYTE first" = "") ), br(), actionButton("submit_analyte", "Submit"),