An interactive Bokeh server application to visualize U.S. tariffs and Trade Restrictiveness Indexes over time.
This application provides an interactive dashboard for tracking and analyzing various tariff metrics for the top 20 U.S. trading partners. It allows users to compare multiple countries, explore different tariff measures, and download both visualizations and data.
- Interactive Time-Series Visualization: View tariff trends from September 2024 to January 2026
- Multiple Tariff Metrics:
- TRI Tariff: Trade Restrictiveness Index (square root tariff)
- Weighted Mean Tariff: 2024 import-weighted average tariff
- Duty / Imports Tariff: Total duties divided by total imports
- Statutory Tariff: Announced tariffs, 2024 import-weighted
- Total Duties: Total customs duties collected (in USD)
- Multi-Country Comparison: Select and compare multiple countries simultaneously
- Visual Indicators: Red shaded region highlights policy periods (Trump 2 administration from April 2025)
- Interactive Tools: Zoom, pan, and hover for detailed information with country flags
- Export Capabilities:
- Download charts as PNG using the toolbar save button
- Export selected data as CSV with a generated download link
The tariff data used in this application is sourced from the Trade War Tracker project:
Repository: https://github.com/tradewartracker/how-restrictive-us-trade
The data is stored in Parquet format at data/tri-all-country-data.parquet and includes historical tariff information for the top 20 U.S. trading partners plus an "ALL COUNTRIES" aggregate.
- Bokeh 3.3.4: Interactive visualization framework
- Pandas 2.1.4: Data manipulation and analysis
- PyArrow 14.0.2: Parquet file handling
- NumPy 1.26.3: Numerical computations
- Python 3.11: Runtime environment
This application is deployed on Heroku as a web dyno running a Bokeh server.
Procfile:
web: bokeh serve --port=$PORT --allow-websocket-origin=tri-tracker-d17ad5511b2b.herokuapp.com --address=0.0.0.0 --use-xheaders main-tri-tracker.py
Key deployment settings:
- Uses Heroku's dynamic
$PORTenvironment variable - Configured for WebSocket connections from the Heroku domain
- Uses
--address=0.0.0.0for proper routing through Heroku's infrastructure - Includes
--use-xheadersto handle Heroku's proxy headers correctly
-
Prerequisites:
- Heroku CLI installed
- Git repository initialized
- Heroku account created
-
Create Heroku app:
heroku create tri-tracker
-
Configure Python buildpack:
heroku buildpacks:set heroku/python
-
Deploy:
git add . git commit -m "Deploy TRI tracker" git push heroku main
-
Open the application:
heroku open
The app will be available at: https://tri-tracker-d17ad5511b2b.herokuapp.com/main-tri-tracker
To run the application locally:
-
Install dependencies:
pip install -r requirements.txt
-
Start the Bokeh server:
bokeh serve --show main-tri-tracker.py
-
Access the application: Open your browser to
http://localhost:5006/main-tri-tracker
TRI-tracker/
├── main-tri-tracker.py # Main Bokeh application
├── Procfile # Heroku deployment configuration
├── requirements.txt # Python dependencies
├── README.md # This file
├── LICENSE # License information
└── data/
└── tri-all-country-data.parquet # Tariff data (Parquet format)
- Select Countries: Use the multi-select dropdown to choose one or more countries to compare
- Choose Metric: Select the tariff metric you want to visualize
- Interact with Chart:
- Hover over lines to see detailed values with country flags
- Click legend items to hide/show specific countries
- Use toolbar to zoom, pan, or reset the view
- Download Chart: Click the save icon (💾) in the chart toolbar
- Download Data: Click "Generate CSV Download Link" button, then click the generated link to download CSV data
- The application uses Bokeh 2.0.0 compatibility for local development (uses
stylesattribute) - Production deployment on Heroku runs Bokeh 3.3.4
- Different metrics may have different date ranges depending on data availability
- CSV export only includes data points where values exist (no empty entries)
See LICENSE file for details.