-
Notifications
You must be signed in to change notification settings - Fork 11
fix: R script and settings export missing volume unit simplification (#1190) #1228
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
6a3272d
f750289
dc64958
be27b41
339b559
aa406cd
b66eec9
4b4de94
5b9b913
e372eb1
f4f71d2
d8b6875
a6de2cf
9d9f9c4
8b53792
1f311a3
f84ee0f
840102e
c511bd1
5b501d3
6b6a464
6b0dcfd
e6ebd6d
a57dcc4
e94ce34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,20 @@ tab_nca_server <- function(id, pknca_data, extra_group_vars, settings_override) | |
| #' should respect the units, regardless of location. | ||
| session$userData$units_table <- reactiveVal(NULL) | ||
|
|
||
| # Keep units_table synchronized with the current dataset. Store the full | ||
| # units table so downstream code never receives a partial units table, and | ||
| # clear it when no units are available to avoid stale values persisting | ||
| # across uploads. | ||
| observeEvent(pknca_data(), { | ||
| current_pknca_data <- pknca_data() | ||
|
|
||
| if (is.null(current_pknca_data) || is.null(current_pknca_data$units)) { | ||
| session$userData$units_table(NULL) | ||
| return() | ||
| } | ||
|
|
||
| session$userData$units_table(current_pknca_data$units) | ||
| }, ignoreNULL = FALSE) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: add a blank line between the |
||
| adnca_data <- reactive(pknca_data()$conc$data) | ||
|
|
||
| # #' NCA Setup module | ||
|
|
@@ -136,9 +150,7 @@ tab_nca_server <- function(id, pknca_data, extra_group_vars, settings_override) | |
| # Update units table | ||
| processed_pknca_data <- processed_pknca_data() | ||
| if (!is.null(session$userData$units_table())) { | ||
| custom_units <- select( | ||
| session$userData$units_table(), -any_of("default") | ||
| ) | ||
| custom_units <- session$userData$units_table() | ||
| by_cols <- intersect(names(processed_pknca_data$units), names(custom_units)) | ||
| by_cols <- setdiff(by_cols, c("PPSTRESU", "conversion_factor")) | ||
| processed_pknca_data$units <- rows_update( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,13 +26,12 @@ units_table_server <- function(id, mydata) { | |||||||||||
|
|
||||||||||||
| modal_units_table <- reactiveVal(NULL) | ||||||||||||
| observeEvent(input$open_units_table, { | ||||||||||||
| default_units <- mydata()$units %>% | ||||||||||||
| dplyr::mutate(default = TRUE) | ||||||||||||
| default_units <- mydata()$units | ||||||||||||
|
|
||||||||||||
| if (!is.null(session$userData$units_table())) { | ||||||||||||
| custom_units <- dplyr::mutate(session$userData$units_table(), default = FALSE) | ||||||||||||
| custom_units <- session$userData$units_table() | ||||||||||||
| by_cols <- intersect(names(default_units), names(custom_units)) | ||||||||||||
| by_cols <- setdiff(by_cols, c("PPSTRESU", "conversion_factor", "default")) | ||||||||||||
| by_cols <- setdiff(by_cols, c("PPSTRESU", "conversion_factor")) | ||||||||||||
| dplyr::rows_update( | ||||||||||||
| default_units, | ||||||||||||
| custom_units, | ||||||||||||
|
|
@@ -102,8 +101,7 @@ units_table_server <- function(id, mydata) { | |||||||||||
| PPORRESU = colDef(name = "Default Unit"), | ||||||||||||
| PPSTRESU = colDef(name = "Custom Unit"), | ||||||||||||
| conversion_factor = colDef(name = "Conversion Factor"), | ||||||||||||
| is_hidden = colDef(show = FALSE), | ||||||||||||
| default = colDef(show = FALSE) | ||||||||||||
| is_hidden = colDef(show = FALSE) | ||||||||||||
| ), | ||||||||||||
| pagination = FALSE, | ||||||||||||
| filterable = TRUE, | ||||||||||||
|
|
@@ -156,7 +154,6 @@ units_table_server <- function(id, mydata) { | |||||||||||
| ) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| modal_units_table[info$row, "default"] <- FALSE | ||||||||||||
| modal_units_table[info$row, "conversion_factor"] <- conversion_factor_value | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -193,7 +190,7 @@ units_table_server <- function(id, mydata) { | |||||||||||
|
|
||||||||||||
| log_trace("Applying custom units specification.") | ||||||||||||
| modal_units_table() %>% | ||||||||||||
| dplyr::filter(!default) %>% | ||||||||||||
| dplyr::filter(!is.na(PPSTRESU), !is.na(PPORRESU), PPSTRESU != PPORRESU) %>% | ||||||||||||
|
||||||||||||
| dplyr::filter(!is.na(PPSTRESU), !is.na(PPORRESU), PPSTRESU != PPORRESU) %>% | |
| dplyr::filter( | |
| (!is.na(PPSTRESU) & !is.na(PPORRESU) & PPSTRESU != PPORRESU) | | |
| dplyr::coalesce(conversion_factor, 1) != 1 | |
| ) %>% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This observer fires on every
pknca_data()invalidation and unconditionally overwritesunits_tablewith the data-derived defaults. Meanwhile,nca_setup.R:175has abindEvent(processed_pknca_data(), once = TRUE)observer that merges imported settings intounits_table.If both observers flush in the same cycle (which happens when
pknca_data()andprocessed_pknca_data()invalidate together during settings import), the execution order is undefined. If this observer runs after the settings import observer, it overwrites the merged units with plain defaults — silently discarding the imported unit overrides.Two possible fixes:
Option A — priority ordering:
Actually, Shiny runs higher-priority observers first. So set this observer to a lower priority so it runs first, then the settings import observer runs after and overwrites with the merged result:
Option B (preferred) — skip when settings import is pending:
observeEvent(pknca_data(), { current_pknca_data <- pknca_data() if (is.null(current_pknca_data) || is.null(current_pknca_data$units)) { session$userData$units_table(NULL) return() } # Don't overwrite if a settings import already populated the table # with user-customized units for this dataset if (is.null(session$userData$units_table())) { session$userData$units_table(current_pknca_data$units) } }, ignoreNULL = FALSE)Option B is simpler and avoids the priority dance. The settings import observer will still merge on top when
processed_pknca_data()fires, and on re-uploadunits_tableis cleared toNULLfirst (line 98-99), so the guard passes correctly.