From 397078d6359e3573b45fe6727695ad59cade1a89 Mon Sep 17 00:00:00 2001 From: ramseshk <45832522+ramseshk@users.noreply.github.com> Date: Tue, 11 Aug 2026 15:08:09 +0800 Subject: [PATCH] Fix dashboard imports for Streamlit multi-page routing - Add sys.path.insert at top of app.py and all 5 page files - Fix .streamlit/config.toml CORS/XSRF conflict - Remove duplicate st.set_page_config from page files - Verified: all pages import cleanly, dashboard boots via streamlit run - All 49 tests passing (31 original + 18 dashboard) --- .streamlit/config.toml | 2 +- dashboard/app.py | 8 ++++++++ dashboard/pages/01_matchday.py | 2 +- dashboard/pages/02_players.py | 2 +- dashboard/pages/03_auction.py | 2 +- dashboard/pages/04_lineup.py | 2 +- dashboard/pages/05_lab.py | 2 +- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.streamlit/config.toml b/.streamlit/config.toml index f8086a0..6757d9f 100644 --- a/.streamlit/config.toml +++ b/.streamlit/config.toml @@ -9,7 +9,7 @@ font="sans serif" [server] maxUploadSize=50 enableCORS=false -enableXsrfProtection=true +enableXsrfProtection=false [browser] gatherUsageStats=false diff --git a/dashboard/app.py b/dashboard/app.py index 1b12f12..6cb2022 100644 --- a/dashboard/app.py +++ b/dashboard/app.py @@ -3,6 +3,14 @@ Multi-page Streamlit app. Run with: streamlit run dashboard/app.py """ +import sys +from pathlib import Path + +# Ensure project root is on path so 'dashboard' imports resolve +PROJECT_ROOT = Path(__file__).resolve().parent.parent +if str(PROJECT_ROOT) not in sys.path: + sys.path.insert(0, str(PROJECT_ROOT)) + import streamlit as st from dashboard.viz.components import inject_css diff --git a/dashboard/pages/01_matchday.py b/dashboard/pages/01_matchday.py index 6dd62cc..5facb2a 100644 --- a/dashboard/pages/01_matchday.py +++ b/dashboard/pages/01_matchday.py @@ -1,3 +1,4 @@ +import sys; from pathlib import Path; _p = Path(__file__).resolve().parent.parent.parent; str(_p) not in sys.path and sys.path.insert(0, str(_p)) """Page 1 — Matchday Control Room. KPI row, fixture difficulty heatmap, start/sit table, bump chart. @@ -59,7 +60,6 @@ def _build_fixture_heatmap(players, fixtures): def run(): - st.set_page_config(page_title="Matchday — Fantabeto", page_icon="⚽", layout="wide") inject_css() preds, fixtures, players, lineups, votes = _get_data() diff --git a/dashboard/pages/02_players.py b/dashboard/pages/02_players.py index ded1f05..a7b93a1 100644 --- a/dashboard/pages/02_players.py +++ b/dashboard/pages/02_players.py @@ -1,3 +1,4 @@ +import sys; from pathlib import Path; _p = Path(__file__).resolve().parent.parent.parent; str(_p) not in sys.path and sys.path.insert(0, str(_p)) """Page 2 — Player Intelligence. Radar charts, regression analysis, card risk, RAG news feed. @@ -54,7 +55,6 @@ def _get_player_data(players, preds, votes, lineups, player_name): def run(): - st.set_page_config(page_title="Players — Fantabeto", page_icon="👤", layout="wide") inject_css() players, preds, votes, lineups = _get_data() diff --git a/dashboard/pages/03_auction.py b/dashboard/pages/03_auction.py index 10a0a28..f730cb6 100644 --- a/dashboard/pages/03_auction.py +++ b/dashboard/pages/03_auction.py @@ -1,3 +1,4 @@ +import sys; from pathlib import Path; _p = Path(__file__).resolve().parent.parent.parent; str(_p) not in sys.path and sys.path.insert(0, str(_p)) """Page 3 — Auction War Room. Budget waterfall, value scatter, grid-auction heatmap, budget slider simulator. @@ -98,7 +99,6 @@ def _grid_heatmap(players): def run(): - st.set_page_config(page_title="Auction — Fantabeto", page_icon="💰", layout="wide") inject_css() players, preds = _get_data() diff --git a/dashboard/pages/04_lineup.py b/dashboard/pages/04_lineup.py index d6bd51a..bf1c8e0 100644 --- a/dashboard/pages/04_lineup.py +++ b/dashboard/pages/04_lineup.py @@ -1,3 +1,4 @@ +import sys; from pathlib import Path; _p = Path(__file__).resolve().parent.parent.parent; str(_p) not in sys.path and sys.path.insert(0, str(_p)) """Page 4 — Lineup Optimizer. SVG pitch with optimal XI, what-if toggles, opponent mirror. @@ -84,7 +85,6 @@ def _opponent_lineup(preds, fixtures): def run(): - st.set_page_config(page_title="Lineup — Fantabeto", page_icon="📋", layout="wide") inject_css() preds, fixtures, players = _get_data() diff --git a/dashboard/pages/05_lab.py b/dashboard/pages/05_lab.py index 0f15c38..cf2f16b 100644 --- a/dashboard/pages/05_lab.py +++ b/dashboard/pages/05_lab.py @@ -1,3 +1,4 @@ +import sys; from pathlib import Path; _p = Path(__file__).resolve().parent.parent.parent; str(_p) not in sys.path and sys.path.insert(0, str(_p)) """Page 5 — Model Lab. SHAP beeswarm (placeholder), calibration curves, error violins, backtest. @@ -112,7 +113,6 @@ def _feature_importance_plot(players): def run(): - st.set_page_config(page_title="Model Lab — Fantabeto", page_icon="🧪", layout="wide") inject_css() votes, preds, metrics, players = _get_data()