Streamlit Dashboard Guide¶
This page covers running, customizing, and deploying the NHRA Strategic Scenario Dashboard.
Quick Start¶
Running Locally¶
The dashboard will open at http://localhost:8501.
Dashboard Features¶
Tab Overview¶
| Tab | Purpose |
|---|---|
| π Scenario Analysis | Trajectory plots, executive summary, intervention ranking |
| πΈοΈ Strategic Map | D3 interactive network of game relationships |
| π² Game Tree Explorer | Extensive form decision trees for each subgame |
| π₯ LHN Variance | Intra-state local hospital network distribution |
| 𧬠Data Lineage | Parameter evidence traceability |
| βοΈ Validation Scorecard | Backtest performance metrics and ghost overlays |
| π¬ Technical Analytics | Stability regions and global sensitivity analysis |
| π‘οΈ Evidence Manager | Evidence registry and conflict resolution |
| π Forensic Audit | Raw state inspection and parity checking |
Sidebar Controls¶
| Category | Parameters |
|---|---|
| Funding & Valuation | Nominal Cth Share, NEP Growth |
| Operational Capacity | Bed Capacity Index, Discharge Delay |
| Policy & Behaviour | Political Salience, Audit Pressure |
| Clinical & Workforce | Rurality Weight, Cost-Shifting Intensity |
| Patient Choice | GP Out-of-Pocket, Time Value |
Expert Mode¶
Toggle "π§ Expert Strategic Mode" to manually override game equilibria:
- Definition: R (Realism) / E (Strict)
- Bargaining: A (Agree) / D (Defer)
- Cost-Shifting: I (Invest) / S (Shift)
- Discharge: C (Coordinate) / F (Fragment)
- Governance: I (Integrate) / S (Separate)
- Compliance: T (Tight) / L (Light)
Deploying to Streamlit Cloud¶
Prerequisites¶
- GitHub Repository: The app must be in a public GitHub repo (or private with Streamlit Cloud Pro)
- Streamlit Account: Sign up at share.streamlit.io
Step 1: Create requirements.txt¶
Streamlit Cloud uses pip, not Poetry. Create a requirements file:
Step 2: Create .streamlit/config.toml¶
[theme]
primaryColor = "#008080"
backgroundColor = "#FFFFFF"
secondaryBackgroundColor = "#F0F2F6"
textColor = "#262730"
font = "sans serif"
[server]
headless = true
port = 8501
[browser]
gatherUsageStats = false
Step 3: Create streamlit_app.py¶
Streamlit Cloud looks for streamlit_app.py by default. Create a symlink or entrypoint:
# streamlit_app.py
import subprocess
import sys
# Ensure src is in path
sys.path.insert(0, "src")
# Import and run the main dashboard
from scripts.dashboard import main
if __name__ == "__main__":
main()
Step 4: Deploy¶
- Go to share.streamlit.io
- Click "New app"
- Select your repository:
edithatogo/nhra_game - Set branch:
main - Set main file path:
streamlit_app.py - Click "Deploy"
Step 5: Configure Secrets (Optional)¶
For API keys or sensitive config:
- Go to app settings β Secrets
- Add secrets in TOML format:
Access in code:
Performance Optimization¶
JAX Caching¶
The dashboard uses JAX with persistent disk caching:
Streamlit Caching¶
Key functions use @st.cache_data for responsiveness:
@st.cache_data
def cached_run_model(p: Params, years: list[int], n_mc: int = 50):
return run_hybrid(years, p, seed=42, n_mc=n_mc)
Monte Carlo Samples¶
- Lite Mode (default): 50 samples β fast, lower confidence
- SOTA Mode: 1000 samples β slower, high confidence
Toggle via sidebar "π Boost to SOTA Accuracy" button.
Customization¶
Theming¶
Modify apply_custom_theme() in scripts/dashboard.py:
def apply_custom_theme():
st.markdown("""
<style>
:root {
--primary-color: #008080; /* Teal */
}
.stMetric {
border-left: 5px solid #008080;
}
</style>
""", unsafe_allow_html=True)
Adding New Tabs¶
- Add to the tabs list:
- Implement tab content:
Adding New Interventions¶
Update the rank_interventions function's intervention list:
And update apply_intervention() in src/nhra_gt/engine.py to handle the new option.
Troubleshooting¶
Common Issues¶
| Issue | Solution |
|---|---|
| Import errors | Add PYTHONPATH=src before running |
| D3 network missing | Run python scripts/interactive/make_d3_network_v26.py |
| Validation data missing | Run python scripts/validation/recursive_backtest.py |
| GSA data missing | Run python scripts/run_gsa.py |
| Slow startup | First run compiles JAX kernels; subsequent runs are cached |
Debug Mode¶
See Also¶
- Usage Guide β General toolkit usage
- Policy Scenarios β Pre-defined scenarios
- Validation β Model validation details