Skip to content

Commit 0a13f97

Browse files
committed
Deploy the Dash app to Fly.io and document both front-ends
- Dockerfile.dash excludes PySpark entirely; the app reads the pre-built Gold parquet, so no JVM ships in the image - .dockerignore keeps venv, docs and the Spark jobs out of the build context - fly.toml pins London, keeps one machine warm (min_machines_running = 1) so the demo link never opens on a cold start, and health-checks / - README gains a Live Dash App section, kept below the static report, which stays the headline because it always loads Image builds and serves: HTTP 200, 26 ms median callback round trip.
1 parent 4f8cb8c commit 0a13f97

4 files changed

Lines changed: 127 additions & 1 deletion

File tree

‎.dockerignore‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
venv/
2+
.git/
3+
data/
4+
!data/gold/analytics_facts.parquet
5+
docs/
6+
dashboards/*.html
7+
dashboards/*.png
8+
generator/
9+
spark/
10+
airflow/
11+
tests/
12+
__pycache__/
13+
*.pyc
14+
.pytest_cache/
15+
.DS_Store

‎Dockerfile.dash‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Dash app image. Deliberately excludes PySpark: the app serves a pre-built
2+
# Gold parquet, so it needs no JVM and no Spark at runtime.
3+
FROM python:3.9-slim
4+
5+
WORKDIR /srv
6+
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
7+
8+
COPY app/requirements.txt ./requirements.txt
9+
RUN pip install --no-cache-dir -r requirements.txt
10+
11+
COPY app/ ./app/
12+
COPY shared/ ./shared/
13+
COPY dashboards/assets/ ./dashboards/assets/
14+
COPY data/gold/analytics_facts.parquet ./data/gold/analytics_facts.parquet
15+
16+
EXPOSE 8080
17+
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--workers", "1", "--threads", "8", \
18+
"--timeout", "60", "--access-logfile", "-", "app.main:server"]

‎README.md‎

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ This project demonstrates many of the technologies and engineering practices use
9999
| CI/CD | GitHub Actions |
100100
| Testing | Pytest |
101101
| Dashboard | Plotly.js, embedded in a self-contained HTML page |
102+
| Live app | Dash (Plotly) served by gunicorn on Fly.io |
102103
| Version Control | Git & GitHub |
103104

104105
---
@@ -113,6 +114,7 @@ This project demonstrates many of the technologies and engineering practices use
113114
- Star Schema Data Warehouse
114115
- Executive dashboard with browser-side cross-filtering across 8 dimensions
115116
- Self-contained, offline-capable HTML report (light and dark themes)
117+
- Live Dash app serving the same report from pandas, sharing one stylesheet
116118
- Automated Apache Airflow Pipeline
117119
- Dockerized Deployment
118120
- Automated Data Quality Testing
@@ -146,6 +148,16 @@ Retail-Data-Engineering-Pipeline/
146148
├── docs/
147149
│ └── index.html # GitHub Pages copy of the dashboard
148150
│
151+
├── app/ # Dash app (live version)
152+
│ ├── main.py # layout + callbacks
153+
│ ├── figures.py # Plotly figures, mirrors app.js
154+
│ ├── components.py # KPI cards, filter bar
155+
│ ├── data.py # loads the Gold parquet, aggregates
156+
│ └── theme.py # reads colour tokens out of app.css
157+
│
158+
├── shared/
159+
│ └── chart_theme.json # chart geometry, read by both front-ends
160+
│
149161
├── data/
150162
│ ├── raw/ # Bronze
151163
│ ├── silver/
@@ -159,7 +171,9 @@ Retail-Data-Engineering-Pipeline/
159171
│
160172
├── .github/workflows/ci.yml
161173
├── docker-compose.yml
162-
├── Dockerfile
174+
├── Dockerfile # Airflow image
175+
├── Dockerfile.dash # Dash app image (no PySpark)
176+
├── fly.toml # Fly.io deployment
163177
└── requirements.txt
164178
```
165179

@@ -299,6 +313,47 @@ Writes `dashboards/executive_dashboard.html` and `docs/index.html` (the GitHub P
299313

300314
---
301315

316+
# 🖥️ Live Dash App
317+
318+
The same report, served by Python instead of precomputed into a file — a **Dash** app in `app/`, deployed to Fly.io.
319+
320+
Why both? A static file can only answer questions it was built to answer. The eight filters combine into **1.6 billion** possible selections, so precomputing them all is impossible; the static build embeds the fact rows and aggregates them in the browser instead. The Dash app aggregates the same rows in pandas, per request. Two answers to the same constraint, and the contrast is the point:
321+
322+
| | Static report | Dash app |
323+
|---|---|---|
324+
| Aggregation | JavaScript, in the browser | pandas, on the server |
325+
| Delivery | one file, opens offline | a running process |
326+
| Hosting | GitHub Pages | Fly.io |
327+
| Filter response | ~70 ms | ~26 ms compute + round trip |
328+
| Always available | yes | yes (machine kept warm) |
329+
330+
### Shared by construction
331+
332+
The two front-ends look identical because they read the same sources, not because anyone kept them in sync by hand:
333+
334+
- **`dashboards/assets/app.css`** — Dash serves this folder directly, so both use one stylesheet
335+
- **`shared/chart_theme.json`** — bar radius, gaps, margins, tick formats
336+
- **Colours** — declared once as CSS custom properties; `app.js` reads them via `getComputedStyle`, `app/theme.py` parses the same declarations
337+
- **`data/gold/analytics_facts.parquet`** — the cleaned fact table both consume (1.6 MB, loads in 9 ms)
338+
339+
The only deliberate duplication is trace assembly: ~150 lines of `app/figures.py` mirroring `app.js`, which no amount of sharing can avoid across two languages.
340+
341+
### Running it
342+
343+
```bash
344+
pip install -r app/requirements.txt
345+
python run_dash.py # http://localhost:8050
346+
```
347+
348+
The Docker image excludes PySpark entirely — the app reads the pre-built parquet, so it needs no JVM at runtime.
349+
350+
```bash
351+
docker build -f Dockerfile.dash -t retailflow-dash .
352+
flyctl deploy
353+
```
354+
355+
---
356+
302357
# 🔄 Apache Airflow
303358

304359
The entire ETL pipeline is fully automated using Apache Airflow.
@@ -408,6 +463,15 @@ python -m pytest tests/ -v
408463

409464
Then open `dashboards/executive_dashboard.html` in a browser.
410465

466+
## Run the Live Dash App
467+
468+
```bash
469+
pip install -r app/requirements.txt
470+
python run_dash.py
471+
```
472+
473+
Serves on `http://localhost:8050`. Needs `data/gold/analytics_facts.parquet`, which the pipeline step above produces.
474+
411475
## Start Airflow
412476

413477
```bash

‎fly.toml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Fly.io deployment for the live Dash dashboard.
2+
# The static report on GitHub Pages stays the headline; this is the
3+
# interactive version, kept warm so the demo link never shows a cold start.
4+
5+
app = "retailflow-dashboard"
6+
primary_region = "lhr"
7+
8+
[build]
9+
dockerfile = "Dockerfile.dash"
10+
11+
[http_service]
12+
internal_port = 8080
13+
force_https = true
14+
auto_start_machines = true
15+
auto_stop_machines = false
16+
min_machines_running = 1
17+
processes = ["app"]
18+
19+
[[vm]]
20+
size = "shared-cpu-1x"
21+
memory = "512mb"
22+
23+
[checks.health]
24+
type = "http"
25+
port = 8080
26+
path = "/"
27+
interval = "30s"
28+
timeout = "5s"
29+
grace_period = "20s"

0 commit comments

Comments
 (0)