Skip to content

Conversation

@d-morrison
Copy link
Member

@d-morrison d-morrison commented Feb 18, 2025

This pull request introduces a new interactive Shiny application for visualizing antigen-antibody kinetics models, along with several supporting functions and package infrastructure updates. It also adds new plotting and mathematical functions for decay curves, exposes additional functions to users, and improves error messaging. The changes enhance the package's interactivity, usability, and extensibility for modeling and visualization.

Major feature: Interactive Shiny app for kinetics modeling

  • Added a new Shiny app (curve_app) for interactively exploring antigen-antibody kinetics, with UI (curve_app_ui), server logic (curve_app_server), and a new launch script (app.R). The app allows users to adjust model parameters via sliders and view real-time plots and derived values. [1] [2] [3] [4]

New modeling and plotting utilities

  • Added antibody_decay_curve and pathogen_decay_curve functions for simulating and plotting antibody and pathogen decay over time. [1] [2]
  • Added plot_decay_curve for easy plotting of decay functions using ggplot2.
  • Introduced helper functions t1f (time to end of active infection) and y1f (peak antibody concentration). [1] [2]

Package infrastructure and configuration

  • Updated .Rbuildignore and added .rscignore to exclude app and deployment files from builds; incremented package version to 1.4.0.9004. [1] [2] [3] [4]
  • Added app_config.R for app-specific configuration and file access helpers.
  • Registered new functions for export and updated NAMESPACE and import statements to support the Shiny app and plotting features. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Error handling improvements

  • Improved error messages in autoplot.seroincidence and autoplot.seroincidence.by to use cli::cli_abort for clearer and more informative errors. [1] [2]

Miscellaneous

  • Added a script to disable shiny autoload in certain contexts (_disable_autoload.R).
  • Minor README and documentation tweaks. [1] [2]

These changes significantly expand the package's capabilities for modeling, visualization, and interactive exploration of serological data.

@codecov
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

❌ Patch coverage is 0.93897% with 211 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
R/curve_app_ui.R 0.00% 85 Missing ⚠️
R/curve_app_server.R 0.00% 59 Missing ⚠️
R/antibody_decay_function.R 0.00% 24 Missing ⚠️
R/plot_decay_curve.R 0.00% 19 Missing ⚠️
R/app_config.R 0.00% 7 Missing ⚠️
R/antigen_decay_curve.R 0.00% 4 Missing ⚠️
R/curve_app.R 0.00% 4 Missing ⚠️
R/autoplot.seroincidence.by.R 40.00% 3 Missing ⚠️
R/t1.R 0.00% 3 Missing ⚠️
R/autoplot.seroincidence.R 0.00% 2 Missing ⚠️
... and 1 more
Files with missing lines Coverage Δ
R/y1.R 0.00% <0.00%> (ø)
R/autoplot.seroincidence.R 30.76% <0.00%> (ø)
R/autoplot.seroincidence.by.R 84.61% <40.00%> (-7.06%) ⬇️
R/t1.R 0.00% <0.00%> (ø)
R/antigen_decay_curve.R 0.00% <0.00%> (ø)
R/curve_app.R 0.00% <0.00%> (ø)
R/app_config.R 0.00% <0.00%> (ø)
R/plot_decay_curve.R 0.00% <0.00%> (ø)
R/antibody_decay_function.R 0.00% <0.00%> (ø)
R/curve_app_server.R 0.00% <0.00%> (ø)
... and 1 more

@d-morrison
Copy link
Member Author

@copilot rebase on main; resolve merge conflicts

Copy link
Contributor

Copilot AI commented Jan 20, 2026

@d-morrison I've opened a new pull request, #486, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 4 commits January 20, 2026 20:47
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
@d-morrison d-morrison marked this pull request as ready for review January 21, 2026 07:11
Copilot AI review requested due to automatic review settings January 21, 2026 07:11
@d-morrison
Copy link
Member Author

@copilot fix failing workflows (lint changed files, add new content to pkgdown config, add entries in changelog, etc)

Copy link
Contributor

Copilot AI commented Jan 21, 2026

@d-morrison I've opened a new pull request, #489, to work on those changes. Once the pull request is ready, I'll request review from you.

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

This pull request adds new antibody and pathogen decay curve modeling functionality to the serocalculator package, including mathematical models for infection dynamics and an interactive Shiny application for visualization.

Changes:

  • New decay curve functions: antibody_decay_curve(), pathogen_decay_curve(), t1f(), y1f(), and plot_decay_curve()
  • Interactive Shiny app (curve_app()) with UI and server components for exploring antigen-antibody kinetics
  • Updated error handling in existing autoplot functions to use cli::cli_abort() instead of stop()
  • New package dependencies: shiny and config for app functionality
  • Presentation formatting improvements to methodology vignette

Reviewed changes

Copilot reviewed 28 out of 30 changed files in this pull request and generated 24 comments.

Show a summary per file
File Description
R/antibody_decay_function.R New function to calculate antibody concentration over time using a two-phase decay model
R/antigen_decay_curve.R New function to calculate pathogen concentration decay
R/t1.R Helper function to calculate time to end of active infection
R/y1.R Helper function to calculate peak antibody concentration
R/plot_decay_curve.R Plotting utility for decay functions
R/curve_app.R Shiny app launcher for interactive kinetics model exploration
R/curve_app_ui.R Shiny UI definition with parameter sliders
R/curve_app_server.R Shiny server logic for reactive plotting
R/app_config.R Golem framework configuration helpers
R/_disable_autoload.R Shiny autoload configuration
R/serocalculator-package.R Added new package imports for ggplot2 and shiny functions
R/autoplot.seroincidence.R Updated to use cli::cli_abort() for error messages
R/autoplot.seroincidence.by.R Updated to use cli::cli_abort() for error messages
DESCRIPTION Added shiny and config dependencies
NAMESPACE Auto-generated exports for new functions
inst/golem-config.yml Golem app configuration
inst/examples/ab-decay-model.Rmd Standalone Shiny document for antibody decay model
app.R Deployment script for Shiny app
.Rbuildignore Excludes app.R and rsconnect from package build
.rscignore Excludes vignettes from RStudio Connect deployment
vignettes/methodology.qmd Presentation formatting with incremental reveals
vignettes/.gitignore Ignores rsconnect deployment files
README.md Minor whitespace formatting
man/*.Rd Auto-generated documentation for new functions

Comment on lines +76 to +88
# plotly::plotlyOutput("plot2")),
shiny::plotOutput(height = "300px", "plot2"),
shiny::sliderInput(
inputId = "ymax2",
label = "log10(ymax)",
min = 0,
max = 5,
step = .1,
value = 1),
# shiny::column(
# width = 6,
h2("antibodies"),
# plotly::plotlyOutput("plot1"))
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

Commented-out code should be removed. These plotly alternatives and column layout code should either be implemented as an option or removed entirely.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,58 @@
#' Graph antibody decay function with natural parameters
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The documentation title says "Graph antibody decay function" but the function is named antibody_decay_curve. The title should match the function's actual purpose. Consider changing the title to "Calculate antibody concentration over time" or "Antibody decay curve" to better reflect what the function does (it returns numeric values, not a graph).

Suggested change
#' Graph antibody decay function with natural parameters
#' Antibody decay curve with natural parameters

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +28
antibody_decay_curve = function(
t,
y0 = 0.74916052, # taken from simpar run from vignette
b0 = 1,
mu_b = 0.18432798,
mu_y = 0.36853621,
gamma = 0.0013040664,
alpha = 0.00002192627,
rho = 2
# rho = 2 # exponential decay?
)
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The function lacks input validation. Consider adding checks for:

  • Negative values for parameters that should be positive (y0, b0, mu_b, mu_y, gamma, alpha)
  • Division by zero when mu_y equals mu_b
  • Invalid values for rho (should typically be >= 1)
    Input validation would make the function more robust and provide clearer error messages to users.

Copilot uses AI. Check for mistakes.
ggplot2::theme_bw() +
# ggplot2::labs(col = "") +
# ggplot2::theme(legend.position = "bottom") +
ggplot2::xlim(0, 100) +
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The xlim is hardcoded to (0, 100) despite having an xmax parameter. The xmax parameter should be used here instead of the hardcoded value 100 to make the function work as documented.

Suggested change
ggplot2::xlim(0, 100) +
ggplot2::xlim(0, xmax) +

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +53


Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

There are empty lines at the end of the function. According to tidyverse style guide and best practices, remove trailing blank lines within functions.

Suggested change

Copilot uses AI. Check for mistakes.
min = -2,
max = 2,
step = .1,
val = 0) |> column(width = 4),
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

Inconsistent spacing around equals sign in sliderInput. Most parameters use consistent spacing, but here there are extra spaces before the equals sign in val = 0 and similar lines. Consider standardizing the spacing throughout the file.

Copilot uses AI. Check for mistakes.
gamma = 0.0013040664,
alpha = 0.00002192627,
rho = 2
# rho = 2 # exponential decay?
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

There's a commented-out line that should be removed. Commented code should not be committed to the codebase. If this is a placeholder for future implementation, consider removing it or using a TODO comment to explain the intent.

Suggested change
# rho = 2 # exponential decay?

Copilot uses AI. Check for mistakes.

plot1 =
shiny::eventReactive(
eventExpr = derived_params() | input$ymax1 | input$alpha | input$rho,
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The eventReactive expression uses the bitwise OR operator | instead of curly braces to combine multiple reactive dependencies. While this may work, the standard Shiny pattern for expressing multiple dependencies is to use curly braces with line breaks or to include them in a list. Consider using eventExpr = {derived_params(); input$ymax1; input$alpha; input$rho} for clarity.

Copilot uses AI. Check for mistakes.

plot2 =
shiny::eventReactive(
eventExpr = derived_params() | input$ymax2,
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The eventReactive expression uses the bitwise OR operator | instead of curly braces to combine multiple reactive dependencies. While this may work, the standard Shiny pattern for expressing multiple dependencies is to use curly braces with line breaks or to include them in a list. Consider using eventExpr = {derived_params(); input$ymax2} for clarity.

Copilot uses AI. Check for mistakes.
d-morrison and others added 2 commits January 20, 2026 23:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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.

2 participants