A Streamlit web app that downloads road safety data from Redash API and generates comprehensive reports on accidents and injuries by road segments and roads.
- Automatic Data Download - Fetches data from Redash API endpoints
- Data Processing - Extracts, merges, and calculates safety metrics
- Real-time Reports - Generates segment-level and road-level accident reports
- Interactive Dashboard - View statistics, data range, and last update
- Data Preview - Browse processed data with sortable tables
- Download Reports - Export all processed data as ZIP file with metadata in filename
all_segments.csv- All road segments with safety metricsall_segments_1_km_and_above.csv- Segments ≥ 1 kmall_roads.csv- Aggregated data by roadall_roads_1_km_and_above.csv- Roads ≥ 1 km
- Total/Fatal/Severe/Light accident counts
- Injuries by severity level
- Safety rates (accidents per km)
- Segment coordinates and locations
- Python 3.8+
- pip or conda
pip install streamlit requests pandas python-dotenvCreate a .env file (or set environment variables):
export ROAD_SEGMENTS_URL=""
export INFOGRAPHICS_URL=""Or copy and edit .env.example:
cp .env.example .envstreamlit run app.pyThe app opens at http://localhost:8501
2026/
├── app.py # Main Streamlit app
├── README.md # This file
├── .env.example # Environment variables template
└── data/
├── source_data/ # Downloaded raw data
└── output_data/ # Generated reports
- Start the app - Streamlit runs automatically on every page load
- Download & Process - Data downloads and processing happens automatically
- View Statistics - See segment/road counts and data range at the top
- Download Reports - Click download button to get all data as ZIP
- Browse Data - Use tabs to view segments or roads with key metrics visible first
This downloads data and processes it without a web interface.
- Road segments data
- Infographics data (accident/injury statistics)
Both return JSON with structure: query_result → data → rows
- Download raw data from Redash API
- Extract accident/injury metrics from JSON
- Merge with road segment information
- Calculate safety metrics (accidents per km, etc.)
- Generate segment and road-level aggregations
- Save to CSV files in
data/output_data/ - Display in interactive Streamlit dashboard
Missing environment variables:
- Ensure
ROAD_SEGMENTS_URLandINFOGRAPHICS_URLare set - Check
.envfile is in the same directory asapp.py