Welcome to amtraklive.com, the website that visualizes the current state of Amtrak's northeast corridor in the style of E.J. Marey's Paris to Lyon train plot.
Built with R, Python, and React.
This website is a final project for Political Science 349: Visualization of Political and Social Data taught by Professor Alexander Coppock at Yale.
This project uses GitHub Actions to automatically:
- Fetch live train data every 3 minutes
- Generate Marey-style plots with R
- Deploy to GitHub Pages for easy integration
- Enable GitHub Actions - See GITHUB_PAGES_SETUP.md for detailed instructions
- Set up GitHub Pages - Configure in repository settings
- Access the API - Data available at
https://YOUR_USERNAME.github.io/YOUR_REPO/api/trains.json
To integrate into your own website:
const API_BASE = 'https://YOUR_USERNAME.github.io/YOUR_REPO';
fetch(`${API_BASE}/api/trains.json`)
.then(res => res.json())
.then(trains => {
// Use train data and plot images
trains.forEach(train => {
console.log(train.id, train.foreground_img, train.background_img);
});
});See INTEGRATION_EXAMPLE.html for a complete example.
data_collector.py- Fetches live train data from Amtracker APIplot_generator.r- Generates Marey-style plots with ggplot2trim_plots.py- Cleans up old plot files.github/workflows/- GitHub Actions automationupdate-plots.yml- Updates train data every 3 minutespages.yml- Deploys to GitHub Pages
frontend/- React frontend (optional local development)
- Python 3.11+
- R 4.3+
- Node.js (for frontend)
# Install Python dependencies
pip install -r requirements.txt
# Install R packages
Rscript -e 'install.packages(c("ggplot2", "dplyr", "lubridate", "grid", "tools"))'
# Run data collection and plot generation
./update.sh
# Start local Flask server (optional)
python app.py
# Start frontend dev server (optional)
cd frontend
npm install
npm run dev-
Data Collection (
data_collector.py)- Fetches real-time train data from Amtracker v3 API
- Filters for Acela and Northeast Regional trains
- Generates CSV files for each active train
- Creates JSON manifest with train metadata
-
Plot Generation (
plot_generator.r)- Reads train CSVs
- Creates Marey-style plots showing:
- Scheduled routes (dashed lines)
- Actual routes (solid lines)
- Current train position (vertical line)
- Generates both background (full schedule) and foreground (current progress) plots
- Creates aggregate plots (All Trains, Northbound, Southbound) and individual train plots
-
Automation (GitHub Actions)
- Runs every 3 minutes via cron schedule
- Commits new plots and JSON data
- Deploys to GitHub Pages automatically
When deployed to GitHub Pages:
GET /api/trains.json- Returns array of train objects with plot URLsGET /plots/{filename}.png- Access individual plot images
All endpoints support CORS for cross-origin access.
See LICENSE for details.