Skip to content

Adding a downloadable PDF report button within Microhub#45

Open
elyfmiller wants to merge 5 commits into
sjfox:mainfrom
elyfmiller:report-pdf
Open

Adding a downloadable PDF report button within Microhub#45
elyfmiller wants to merge 5 commits into
sjfox:mainfrom
elyfmiller:report-pdf

Conversation

@elyfmiller

Copy link
Copy Markdown

Adds a downloadable PDF report to MicroHub: a summary of a SARI forecast run you can
skim or share with others.

Where it is located: a "Download report (PDF)" button in the Download tab. It enables once you've generated an Ensemble, so it is intended to be run right after a run. Claude hard-coded some languages for the PDF generation in EN / ES / PT, not sure if that is correct but we did talk about adding different language features in the future.

The PDF report is designed to be a quick glance at a few things:

  • The data you used. The first page shows the run configuration and an observed-data plot that marks any recent weeks you dropped, so you can check at a glance that dropping them was justified.
  • The quantile forecast. One page per target group (Overall, Adult, Pediatric) with the ensemble probabilistic forecast and the some general "quick-look" numbers.
  • A categorical "outlook." Inspired by Daniel's categorical-forecast report, it translates the quantile forecast into an intuitive read for users less familiar with quantile forecasts: one of five levels (large decrease to large increase), colored green to red, with a per-week strip whose fill height shows how certain the categorical designation is. This can be removed, but I had some whitespace to work with and thought it may be helpful not necessarily for us but for others who are going to be using this tool to advise policy decisions.

The main changes are located in R/report.R plus the Download-tab wiring in server/download.R. Other files are touched including R/install_packages.R because this PDF report requires 2 new R packages and will need to be installed before this works on your device.

elyfmiller and others added 5 commits June 15, 2026 10:57
Adds a "Download Report (.pdf)" action to the Download tab that turns a
completed ensemble run into a styled, single-country PDF report, alongside
the existing CSV and plots-PDF downloads. The button enables once an
Ensemble has been generated.

Report contents (R/report.R):
- Cover: a one-line overall outlook, the run-configuration & data-handling
  table, and an observed-data plot (no forecast) arguing the configuration.
  The title carries the country ("MicroHub Forecast Report - Chile"); the
  banner font auto-shrinks so long country names cannot overflow.
- One page per target group (Overall first): a plain-language narrative, an
  ensemble forecast plot (this season vs the same weeks last season, with
  50%/90% prediction intervals and dropped/nowcast weeks marked), and a 2x2
  grid of KPI tiles -- projected 4-week change, estimated SARI over the next
  4 weeks (sum of the forward weekly medians), vs last season, and season
  peak so far.

KPI colours: the two percent-change tiles use a diverging scale (a decrease
shades green, ~0% is neutral grey, an increase shades yellow -> orange -> red
by magnitude; the 8%/20% cut-points are a transparent heuristic in the spirit
of the FluSight/PAHO 5-level trend framing, not empirically derived per zone).
The cumulative tile has its own standalone colour, distinct from the others.

Rendering uses the base grDevices::pdf() device + ggplot2/cowplot/gridExtra/
ggtext (no LaTeX/pandoc), matching the existing plots-PDF export.

Internationalisation: every reader-facing string lives in a per-language
dictionary (English/Spanish/Portuguese) using official PAHO/WHO terminology
(SRAG in pt, IRAG in es, "pronostico de conjunto", "intervalo de prediccion",
"rezago de datos"); dates, month names and thousands/decimal separators are
localised. A "Report language" selector on the Download tab drives it and is
appended to the downloaded filename.

Season-scoped stats: the WHO transmission zone (input$seasonality, A-E) is
mapped to a season window by hemisphere, matching the A/B/C vs D/E split in
baseline-seasonal.R, so "peak so far"/"last season" and the season labels are
correct for both hemispheres. The zone code is shown alongside the derived
hemisphere, e.g. "Chile (E, southern)".

Robustness: report generation is wrapped so a failure can never escape the
download handler -- an unhandled error there can tear down the Shiny session
and leave the whole app greyed out until restart. On failure it writes a valid
one-page fallback PDF (localised) and the app keeps running. The quantile
pivot tolerates an ensemble missing an expected level, and gaps in the
observed series no longer warn.

New runtime dependencies (declared in app.R): ggtext, gridExtra, scales.

Wired up in: app.R (source + libraries), ui/tab_download.R (button +
language selector), server/download.R (downloadHandler + enable observer),
server/init.R (disable on init/reset).
Each per-group page now leads with a categorical "outlook": the ensemble
quantiles become a 5-level forecast (large decrease to large increase) driven by
the median, with a per-week "weekly trend & certainty" strip whose fill height
shows the certainty of the categorical designation. The category anchors to the
model's nowcast of the latest used week, so an incomplete final week can't fake a
jump. Replaces the old 2x2 KPI grid with a single outlook tile plus three
reference cards (cumulative SARI, vs last season, season peak).

Cover: the run dates move into a labeled metadata card under the banner (forecast
date / report generated / latest data week), and the config table drops the now
duplicated rows.

Declares the report's direct plotting deps (scales, gridExtra, ggtext) in
install-packages.R.
app.R's library(gridExtra)/library(ggtext) (for the PDF report) need these in the published image; the Dockerfile installs CRAN deps separately from install-packages.R.
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.

1 participant