Skip to content

Commit d8895bb

Browse files
authored
Add global theme toggle and enhanced styling (#30)
1 parent 879eee1 commit d8895bb

9 files changed

Lines changed: 42 additions & 11 deletions

File tree

TODO.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ After completing a milestone, create a pull request with your changes for review
201201
- [x] Enforce maximum file size during upload
202202
- [x] Add tests covering oversized file uploads
203203

204+
## PR20: Theme Improvements
205+
206+
- [x] Extend sidebar and Plotly figure styling for both themes
207+
- [x] Add global theme toggle stored in session state
208+
- [x] Update tests to verify theme CSS output
209+
204210
## Notes for Development
205211

206212
- Create comprehensive commit messages that clearly describe changes

app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
st.set_page_config(page_title="PredictStream", layout="wide")
1010

11+
if "theme" not in st.session_state:
12+
st.session_state["theme"] = "Light"
13+
14+
ui.apply_theme(st.session_state["theme"])
15+
1116

1217
def main() -> None:
1318
"""Render the home page with navigation links."""
@@ -17,6 +22,7 @@ def main() -> None:
1722
"Use the sidebar to navigate to different sections of the application."
1823
)
1924
with st.sidebar:
25+
st.selectbox("Theme", ["Light", "Dark"], key="theme")
2026
st.page_link("app.py", label="Home", icon="🏠")
2127
st.page_link("pages/data_explorer.py", label="Data Explorer", icon="📊")
2228
st.page_link("pages/modeling.py", label="Modeling", icon="🧠")

pages/data_explorer.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ def main() -> None:
1717
"""Render the data exploration and modeling page."""
1818
ui.apply_branding()
1919
st.title("Data Explorer")
20-
theme = st.sidebar.selectbox(
21-
"Theme",
22-
["Light", "Dark"],
23-
help="Toggle interface theme",
24-
key="theme",
25-
)
26-
st.markdown(ui.get_theme_css(theme), unsafe_allow_html=True)
20+
ui.apply_theme()
2721

2822
with st.expander("Getting Started"):
2923
st.markdown(ui.getting_started_markdown())

pages/modeling.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def main() -> None:
3232
"""Render the modeling page."""
3333
ui.apply_branding()
3434
st.title("Modeling")
35+
ui.apply_theme()
3536

3637
data_keys = _available_datasets()
3738
if not data_keys:

pages/prediction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def main() -> None:
2222
"""Render the prediction page."""
2323
ui.apply_branding()
2424
st.title("Prediction")
25+
ui.apply_theme()
2526

2627
with st.sidebar:
2728
mode = st.radio("Mode", ["Single", "Batch"], key="pred_mode")

pages/report.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def main() -> None:
2222
"""Render the report generation page."""
2323
ui.apply_branding()
2424
st.title("Report Generator")
25+
ui.apply_theme()
2526

2627
with st.sidebar:
2728
data_utils.upload_data_to_session(

pages/time_series.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def main() -> None:
1818
"""Render the time series analysis page."""
1919
ui.apply_branding()
2020
st.title("Time Series Analysis")
21+
ui.apply_theme()
2122

2223
df = st.session_state.get("data")
2324
if df is None or df.empty:

tests/test_ui.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55

66
def test_get_theme_css():
7-
css = ui.get_theme_css("Dark")
8-
assert "background-color" in css
7+
light = ui.get_theme_css("Light")
8+
dark = ui.get_theme_css("Dark")
9+
for css in (light, dark):
10+
assert "stSidebar" in css
11+
assert "plotly-chart" in css
912

1013

1114
def test_getting_started_markdown():

utils/ui.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@
88
import streamlit as st
99

1010
THEME_CSS: Dict[str, str] = {
11-
"Light": "",
12-
"Dark": "body { background-color: #0e1117; color: #f0f0f0; }",
11+
"Light": """
12+
<style>
13+
[data-testid='stSidebar'] {background-color: #f0f2f6;}
14+
.plotly-chart .main-svg {background-color: #ffffff;}
15+
</style>
16+
""",
17+
"Dark": """
18+
<style>
19+
body {background-color: #0e1117; color: #f0f0f0;}
20+
[data-testid='stSidebar'] {background-color: #262730;}
21+
.plotly-chart .main-svg {background-color: #0e1117;}
22+
</style>
23+
""",
1324
}
1425

1526
# Branding colors
@@ -31,6 +42,13 @@ def get_theme_css(theme: str) -> str:
3142
return THEME_CSS.get(theme, "")
3243

3344

45+
def apply_theme(theme: str | None = None) -> None:
46+
"""Apply the selected theme's CSS to the app."""
47+
if theme is None:
48+
theme = st.session_state.get("theme", "Light")
49+
st.markdown(get_theme_css(theme), unsafe_allow_html=True)
50+
51+
3452
def getting_started_markdown() -> str:
3553
"""Return markdown text for the getting started guide."""
3654
return (

0 commit comments

Comments
 (0)