Skip to content

feat: filter slope selector plots to show only flagged profiles#1267

Draft
Gero1999 wants to merge 10 commits into
mainfrom
1265-enhancement/slope-selector-flag-filter
Draft

feat: filter slope selector plots to show only flagged profiles#1267
Gero1999 wants to merge 10 commits into
mainfrom
1265-enhancement/slope-selector-flag-filter

Conversation

@Gero1999

Copy link
Copy Markdown
Collaborator

Issue

Closes #1265

Description

When a study has hundreds of profiles, finding the ones that need manual half-life adjustment is tedious. This PR adds a "Show only flagged profiles" checkbox to the slope selector that filters plots to only show profiles violating the flag rules defined in NCA Settings (R2ADJ, R2, LAMZSPN). Profiles where lambda.z failed entirely are always shown.

Changes

  • R/get_halflife_plots.R: Add r.squared to the PPTESTCD filter in .merge_conc_with_nca_results so it's available in the per-profile data alongside adj.r.squared and span.ratio.
  • inst/shiny/functions/utils-slope_selector.R:
    • Update handle_hl_adj_change, handle_interval_change, and update_plots_with_pknca to pass through and return both plots and data (previously only plots were returned).
    • Add .get_flagged_profile_ids() helper that evaluates per-profile NCA results against checked flag rules.
  • inst/shiny/modules/tab_nca/setup/slope_selector.R:
    • Add plot_profile_data reactiveVal to capture the data output from get_halflife_plots().
    • Add "Show only flagged profiles" checkbox in the plot widgets row.
    • Add filtered_plot_outputs reactive that applies the flag filter before pagination/search.
    • Add observer to disable the checkbox when no half-life flag rules (R2ADJ, R2, LAMZSPN) are checked.
    • Accept new flag_rules parameter.
  • inst/shiny/modules/tab_nca/nca_setup.R: Extract flag_rules reactive from settings() and pass it to slope_selector_server.

Definition of Done

  • Checkbox appears next to search/pagination controls in slope selector
  • When checked, only profiles violating at least one active flag rule are shown
  • Profiles with lambda.z = NA (failed fit) are always shown when filter is active
  • Checkbox is disabled (greyed out) when no half-life flag rules are checked in NCA Settings
  • Pagination and search operate on the filtered set
  • When all profiles pass, a message is shown instead of empty space
  • Unchecking the checkbox restores all profiles

How to test

  1. Upload a dataset → Run NCA with flag rules checked (e.g. R2ADJ < 0.9, LAMZSPN < 2)
  2. Go to Slope Selector → verify the checkbox appears next to the search controls
  3. Check the checkbox → verify only profiles with R2ADJ < 0.9 or span ratio < 2 (or failed lambda.z) are shown
  4. Uncheck → verify all profiles return
  5. Go to NCA Settings → uncheck all flag rules → verify the checkbox is disabled and unchecked
  6. Re-check a flag rule → verify the checkbox becomes enabled again

Contributor checklist

  • Code passes lintr checks
  • Code passes all unit tests
  • New logic covered by unit tests
  • New logic is documented
  • App or package changes are reflected in NEWS
  • Package version is incremented
  • R script works with the new implementation (if applicable)
  • Settings upload works with the new implementation (if applicable)
  • If any .scss change was done, run data-raw/compile_css.R
  • If a package dependency was added/changed, run data-raw/test_suggests_hidden.R

Notes to reviewer

The data output from get_halflife_plots() was already computed but discarded by the caller. This PR captures it with minimal overhead. The flag evaluation uses the same NCA results that annotate the plots (R²adj, span ratio in the subtitle), so the filter is consistent with what the user sees.

AUCPEO and AUCPEP flags are intentionally excluded — they are AUC extrapolation metrics not available in the slope selector data."

Gero1999 and others added 10 commits April 28, 2026 08:42
Add r.squared to the PPTESTCD filter in .merge_conc_with_nca_results
so it is available alongside adj.r.squared and span.ratio in the
per-profile data returned by get_halflife_plots().

Co-authored-by: Ona <no-reply@ona.com>
Store the data output from get_halflife_plots in a new plot_profile_data
reactiveVal alongside plot_outputs. Update handle_hl_adj_change,
handle_interval_change, and update_plots_with_pknca to pass through and
return both plots and data so profile-level NCA results (adj.r.squared,
r.squared, span.ratio) are available for filtering.

Co-authored-by: Ona <no-reply@ona.com>
Extract flag_rules reactive from settings() in nca_setup.R and pass it
to slope_selector_server. Update the function signature to accept the
new parameter with a default of reactive(NULL).

Co-authored-by: Ona <no-reply@ona.com>
…1265)

Place the checkbox in the plot-widgets-container row next to the
plots-per-page and search-subject controls.

Co-authored-by: Ona <no-reply@ona.com>
Add .get_flagged_profile_ids() helper that evaluates per-profile NCA
results (adj.r.squared, r.squared, span.ratio) against checked flag
rules. Profiles with lambda.z = NA (failed fit) are always shown.

Add filtered_plot_outputs reactive in slope_selector_server that applies
the filter when the checkbox is checked. Pagination and search now
operate on the filtered set. Show a specific message when all profiles
pass the flag rules.

Co-authored-by: Ona <no-reply@ona.com>
)

Add an observer that watches flag_rules() and disables the checkbox
(unchecking it first) when none of the half-life flag rules (R2ADJ, R2,
LAMZSPN) are active. Re-enables when at least one is checked.

Co-authored-by: Ona <no-reply@ona.com>
The function was referenced in slope_selector.R but its definition was
not included in the previous commit. Add it to utils-slope_selector.R.
The function was referenced in slope_selector.R but its definition was
not included in the earlier commit.
Bring in latest main changes (CI workflow updates, merged PRs).
Co-authored-by: Ona <no-reply@ona.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: filter slope selector plots to show only flagged profiles

1 participant