diff --git a/inst/shiny/tabs/nca.R b/inst/shiny/tabs/nca.R index b82db7a..5bf611e 100644 --- a/inst/shiny/tabs/nca.R +++ b/inst/shiny/tabs/nca.R @@ -278,11 +278,24 @@ output$datatable <- renderReactable({ # IN this tab we can set the dose number to be analyzed, the extrapolation # method, potenital partial AUC and all the flag rule sets - -# Define the profiles (dosno) associated with each patient (usubjid) for the selected analyte -profiles_per_patient <- reactiveVal(NULL) -observeEvent(mydata(), { - profiles_per_patient(tapply(mydata()$conc$data$DOSNO, mydata()$conc$data$USUBJID, unique)) +# Define a profiles per patient +profiles_per_patient <- reactive({ + req(mydate()) + + # Check if res_nca() is available and valid + if (!is.null(res_nca())) { + res_nca()$result %>% + mutate(USUBJID = as.character(USUBJID), + DOSNO = as.character(DOSNO)) %>% + group_by(USUBJID, ANALYTE, PCSPEC) %>% + summarise(DOSNO = unique(DOSNO), .groups = "drop") %>% + unnest(DOSNO) # Convert lists into individual rows + } else { + mydata()$conc$data %>% + mutate(USUBJID = as.character(USUBJID)) %>% + group_by(USUBJID, ANALYTE, PCSPEC) %>% + summarise(DOSNO = list(unique(DOSNO)), .groups = "drop") + } }) # Include keyboard limits for the settings GUI display