Skip to content

Conversation

@Gero1999
Copy link
Collaborator

@Gero1999 Gero1999 commented Sep 12, 2025

Description

This changes simplify the logic that makes the slope plots in order to make easier future implementations and also make able the download of all plots in a zip file easily. The advantages would be:

Features

  • Slope order input. Users can group their plots in whatever way they want them to appear.

Enhancements

  • All plots are generated, instead of only the rendered ones.
  • The new function that generates plots is faster and more aligned with PKNCA (get_halflife_plot)
  • Only modified plots are affected by changes, reducing unnecessary plot redraws
  • Upstream, the PKNCA object is updated with the slope rules directly in setup.R, instead of in the post-processing of results. We no longer need to use filter_slopes
  • We no longer use the custom is.included.hl or is.excluded.hl that then are used to build exclude_half.life. Instead we directly use the exclude_half.life & include_half.life columns
  • Added more documentation and comments
  • The new reactivity flow to create the plots that allows a simpler use of settings. We just simply need to udpate the dataset and/or manual slopes and everything will be auto-managed:
#' processed_pknca_data (input, from parent)
#'   └─> slope_selector_server
#'        ├──> plot_outputs (reactive, updated by processed_pknca_data changes)
#'        └──> ├> handle_plotly_click (updates manual_slopes on plot click)
#'                   └> handle_table_edits (updates manual_slopes on user edits & setting overrides)
#'                          └─> manual_slopes (output, used by parent to update processed_pknca_data)

Bugs fixed

  • Pagination controls are less likely to break (unless you are a clicking psycho 💀)
  • Exclusion/Inclusion of points or table edits won't reset subject search
  • Units appear for the Y axis

Tests

  • Setup FIXTURE_PKNCA_DATA obj will now contain the columns include_half.life, exclude_half.life

Definition of Done

Closes or contributes to #333 (I think with this the client interest is already satisfied)

  • Grouping option for slopes plots
  • Faceting so groups are all on one page

Closes #553

  • Logic was simplified and code refactored
  • All Slope Selector features work well without issues
  • Make a folder Slope selector including its plots

How to test

How to test features not covered by unit tests.

Contributor checklist

  • Code passes lintr checks
  • Code passes all unit tests
  • New logic covered by unit tests
  • New logic is documented
  • Package version is incremented

Notes to reviewer

Compare thoughtfully the feats of the plots to make sure I did not miss anything relevant.
Don't hesitate also to leave suggestions for refactoring or code comments that makes the code easier to read.

TODO: mydata is affected by parameters and is affecting manual_slopes!
Copilot AI review requested due to automatic review settings January 5, 2026 15:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 38 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +81 to +87
new_row <- cbind(
first_group,
data.frame(
TYPE = "Exclusion",
RANGE = paste0(
inner_join(first_group, pknca_data()$conc$data)[[time_col]][2]
),
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner_join on line 86 may fail or produce unexpected results if first_group contains NA values or if there's no matching row in the concentration data. Consider adding error handling or validation to ensure the join succeeds and that at least 2 rows exist before accessing the second element with [2].

Suggested change
new_row <- cbind(
first_group,
data.frame(
TYPE = "Exclusion",
RANGE = paste0(
inner_join(first_group, pknca_data()$conc$data)[[time_col]][2]
),
# Safely join to concentration data and derive a time value for the RANGE column
joined_conc <- inner_join(first_group, pknca_data()$conc$data)
if (!is.null(time_col) && time_col %in% names(joined_conc) && nrow(joined_conc) > 0) {
if (nrow(joined_conc) >= 2) {
range_value <- joined_conc[[time_col]][2]
} else {
# Fallback to the first available time if only one row is present
range_value <- joined_conc[[time_col]][1]
}
} else {
# If join fails or time column is unavailable, use NA to avoid runtime errors
range_value <- NA_character_
}
new_row <- cbind(
first_group,
data.frame(
TYPE = "Exclusion",
RANGE = paste0(range_value),

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +56
grepl(
paste0("USUBJID=(", paste0(search_val, collapse = ")|("), ")"),
names(plot_outputs())
)
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search pattern on line 54 hardcodes "USUBJID" as the grouping variable for filtering plots. If the data uses a different subject identifier column name, this search will not work correctly. Consider making the subject column name configurable or dynamically detecting it from the pknca_data object.

Copilot uses AI. Check for mistakes.
Gero1999 and others added 2 commits January 6, 2026 10:52
Co-authored-by: Mateusz Kołomański <63905560+m-kolomanski@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 6, 2026 10:27
@Gero1999 Gero1999 review requested due to automatic review settings January 6, 2026 10:27
Copilot AI review requested due to automatic review settings January 7, 2026 07:15
@Gero1999 Gero1999 review requested due to automatic review settings January 7, 2026 07:16
@Gero1999
Copy link
Collaborator Author

Gero1999 commented Jan 7, 2026

@js3110 regarding the very specific user bugs:

If I add an exclusion, run NCA, then go back to setup and remove the exclusion, I get this error:
Warning: Error in if: missing value where TRUE/FALSE needed

This is fixed

If I run through the workflow quite fast, and add an exclusion, I clikc the run NCA buton then nothing happens. I wait a few seconds and click again then nothing happens, repeat. Then eventually it runs and it Runs NCA like 3 times. Has happened to me twice now so I know its a real bug- but hard to recreate unorganically...

This I was not able to replicate it neither here nor in main. Maybe was fixed with after the merge. Otherwise please share me a screen recording and the console messages and I will try to look into it


@m-kolomanski regarding the suggestions:

Most of them were addressed. Some style changes specifically for get_halflife_plots.R I will in principle not implement them because they conflict with PKNCA style, and the function might likely be transferred there at some point

@Gero1999 Gero1999 marked this pull request as ready for review January 7, 2026 09:09
Copy link
Collaborator

@js3110 js3110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Gero1999 , thanks, the bugs from before don't seem to be there anymore!

Unfortunately I ran into some other issues:

If I add a selection it doesn't update the plot:
image

If I click all the way to the end, I then can't change page anymore:

image

I also got an error after adding the following selections/exclusions:
image

ERROR [2026-01-07 11:08:17] Error calculating NCA results:
ℹ In index: 13.
Caused by error in `assert_numeric_between()`:
! Please report a bug.
: Error with interval start=0, end=24.018: Assertion on 'lambda.z' failed: Element 1 is not > 0

It worked after I removed the selection. I tried a different selection and this time it worked (the plot updated but only after I ran the NCA)

I removed an exclusion and ran the NCA again, then when I went to add it back it added two rows to the table:
image

Now every time I try to add a new exclusion/selection it adds all the previous ones too:

Screen.Recording.2026-01-07.111559.mp4

@Gero1999 Gero1999 marked this pull request as draft January 8, 2026 08:51
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: Download of Visualization & Individual slope plots

5 participants