> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 0013. One Streamlit dashboard, on a laptop and hosted, with a live feed

* **Date:** 2026-11-25
* **Status:** Agreed 2026-11-25 (proposed by Mahad)
* **Agreed by:** Mahad (2026-11-25), for the team

## Context

Decision 0010 put a static HTML page on Hugging Face next to the Streamlit dashboard of decision 0008. That meant two dashboards that could drift apart, and the hosted one could only replay a recording. We want to demo a hosted dashboard (nothing to start on a laptop), the same one teammates run locally, and able to show a real run as it happens.

What we checked on 2026-11-25:

* Hugging Face runs Streamlit only as a Docker Space, which needs the PRO plan (\$9 a month).
* Streamlit Community Cloud is free for public apps, deploys from a github.com repository, and sleeps after 12 hours without visitors (one click wakes it).
* stlite (Streamlit in the browser) is free but slow to open, and lags behind current Streamlit versions.

## Decision

* **One app: `src/dashboard/app.py`**, run with `streamlit run` on a laptop and hosted free on Streamlit Community Cloud (`common.settings.DASHBOARD_URL`). It has four views:
  * **Live stream:** this computer's `data/stream/`, or the online live feed;
  * **Replay:** the recorded stream, played day by day, for any range of years (by default the model's test years, 2024–2025; earlier years carry a warning that the model was trained on them);
  * **Event history & forecast:** the CAR path per year, the trend to the next year and the model by event day;
  * **About.**
* **The hosted copy** is a github.com repository that `scripts/sync_dashboard_app.sh` fills after every commit. It holds only the code the app imports, `config/`, the snapshot and `hosting/streamlit/` (requirements, theme, README).
* **The Hugging Face Space** stays free (static): `hosting/space/index.html` embeds the hosted app. The old HTML/JavaScript page is removed.
* **The live feed:** with `--publish-live`, `src/streaming/job.py` uploads each finished micro-batch, every 15 seconds and in one commit, to the public Hugging Face dataset `common.settings.LIVE_REPO`. Safeguards (2026-11-25):

  * it runs only when the computer is signed in to Hugging Face with write access to the team's organisation and writes to a local folder; otherwise the job stops at once and says why;
  * every run uploads into its own folder and becomes the run the dashboard shows only when no other run is streaming, so one person's run cannot take over another's demo;
  * each run carries its runner's first name.
  * `scripts/demo_live.sh` runs the demo in one command: it sets Java 21, replays from mid-2023 into `data/demo/` and streams with `--publish-live`.

  The upload drops the columns in `hosting.live.NOT_PUBLISHED`. The hosted app copies the newest run and reads it like a local folder, only batches with `_SUCCESS`.
* **The snapshot is committed** in `hosting/snapshot/`: the replay, the event history and the build info (about 1 MB of derived statistics), so the hosted app and a fresh clone both show them. This is a deliberate exception to AGENTS.md rule 4.

## Alternatives considered

* **Hugging Face PRO with a Docker Space:** \$9 a month for the same app.
* **Keeping the static page:** a second dashboard to maintain, and no live runs.
* **Pushing every micro-batch to Hugging Face at once:** too many commits for its rate limits. Grouping them every 15 seconds is enough for a demo.

## Consequences

* **New files:**
  * `src/hosting/live.py`, `scripts/sync_dashboard_app.sh`, `hosting/streamlit/`;
  * the `--publish-live` and `--publish-every` options of `job.py`, and `scripts/demo_live.sh`;
  * `common.settings` entries `SNAPSHOT_DIR`, `APP_BUNDLE_DIR`, `DASHBOARD_URL`, `LIVE_REPO`, `LIVE_CACHE_DIR` and `LINKS`.
* **Tests:** `tests/test_dashboard.py` runs every view headless, offline. `tests/test_hosting.py` checks that a live batch is published without price columns and only once finished.
* **Demo:**
  1. Open the hosted app a minute early, to wake it.
  2. Start the cloud streamer (decision 0015), or, on a computer signed in to Hugging Face, run `scripts/demo_live.sh`. Stop it with *Cancel run* or Ctrl-C.
  3. The app opens on *Live stream* while the run streams.
* **No contract changes.**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.