Johannes commited on
Commit
16cd567
Β·
1 Parent(s): 5713ffb

Responsive Design: mobile Layout via streamlit-javascript

Browse files
Files changed (2) hide show
  1. app.py +14 -3
  2. requirements.txt +1 -0
app.py CHANGED
@@ -61,6 +61,15 @@ st.set_page_config(
61
  inject_css()
62
 
63
 
 
 
 
 
 
 
 
 
 
64
  # ── Home page ──────────────────────────────────────────────────────────────────
65
 
66
  def render_home():
@@ -75,7 +84,8 @@ def render_home():
75
  """, unsafe_allow_html=True)
76
 
77
  # Feature tiles
78
- col1, col2, col3 = st.columns(3)
 
79
  with col1:
80
  st.markdown("""<div class="at-feature-box">
81
  <div class="at-feature-icon">πŸ—ΊοΈ</div>
@@ -422,7 +432,8 @@ def main():
422
  2: "LΓ€nder + Vergleich BundeslΓ€nder",
423
  3: "Bundesland + Vergleich Kommunen",
424
  }
425
- with st.expander("βš™οΈ Einstellungen", expanded=False):
 
426
  _eu_names = sorted(EUROPEAN_COUNTRIES.keys())
427
  def _mob_scale_change():
428
  st.session_state["dl_option"] = st.session_state["_mob_scale"]
@@ -577,7 +588,7 @@ def main():
577
  current_n = int(trend_df[trend_df["year"] == CURRENT_YEAR]["count"].sum())
578
  peak_year = int(trend_df.loc[trend_df["count"].idxmax(), "year"])
579
 
580
- col1, col2, col3 = st.columns(3)
581
  col1.metric(f"Gesamt {y_from}–{y_to}", f"{total_all:,}")
582
  col2.metric(f"Funde {CURRENT_YEAR} (live)", f"{current_n:,}")
583
  col3.metric("Jahr mit meisten Funden", str(peak_year))
 
61
  inject_css()
62
 
63
 
64
+ # ── Responsive: Bildschirmbreite einmalig messen ───────────────────────────────
65
+ def _is_mobile() -> bool:
66
+ if "screen_width" not in st.session_state:
67
+ from streamlit_javascript import st_javascript
68
+ w = st_javascript("window.innerWidth")
69
+ st.session_state["screen_width"] = int(w) if w else 1200
70
+ return st.session_state["screen_width"] < 768
71
+
72
+
73
  # ── Home page ──────────────────────────────────────────────────────────────────
74
 
75
  def render_home():
 
84
  """, unsafe_allow_html=True)
85
 
86
  # Feature tiles
87
+ mobile = _is_mobile()
88
+ col1, col2, col3 = st.columns(1 if mobile else 3)
89
  with col1:
90
  st.markdown("""<div class="at-feature-box">
91
  <div class="at-feature-icon">πŸ—ΊοΈ</div>
 
432
  2: "LΓ€nder + Vergleich BundeslΓ€nder",
433
  3: "Bundesland + Vergleich Kommunen",
434
  }
435
+ mobile = _is_mobile()
436
+ with st.expander("βš™οΈ Einstellungen", expanded=mobile):
437
  _eu_names = sorted(EUROPEAN_COUNTRIES.keys())
438
  def _mob_scale_change():
439
  st.session_state["dl_option"] = st.session_state["_mob_scale"]
 
588
  current_n = int(trend_df[trend_df["year"] == CURRENT_YEAR]["count"].sum())
589
  peak_year = int(trend_df.loc[trend_df["count"].idxmax(), "year"])
590
 
591
+ col1, col2, col3 = st.columns(1 if _is_mobile() else 3)
592
  col1.metric(f"Gesamt {y_from}–{y_to}", f"{total_all:,}")
593
  col2.metric(f"Funde {CURRENT_YEAR} (live)", f"{current_n:,}")
594
  col3.metric("Jahr mit meisten Funden", str(peak_year))
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  streamlit>=1.57.0
2
  huggingface_hub>=0.23.0
 
3
  streamlit-folium>=0.27.0
4
  pygbif>=0.6.6
5
  geopandas>=1.0.0
 
1
  streamlit>=1.57.0
2
  huggingface_hub>=0.23.0
3
+ streamlit-javascript>=0.1.5
4
  streamlit-folium>=0.27.0
5
  pygbif>=0.6.6
6
  geopandas>=1.0.0