Adding a downloadable PDF report button within Microhub#45
Open
elyfmiller wants to merge 5 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 main changes are located in
R/report.Rplus the Download-tab wiring inserver/download.R. Other files are touched includingR/install_packages.Rbecause this PDF report requires 2 new R packages and will need to be installed before this works on your device.