fmegahed commited on
Commit
3b66818
·
1 Parent(s): 65b5ca1

Fix continuous rerun loop: remove default=/index=/value= from keyed widgets

Browse files
Files changed (1) hide show
  1. app.py +24 -22
app.py CHANGED
@@ -305,16 +305,15 @@ with st.sidebar:
305
  all_cols = list(raw_df.columns)
306
  default_date_idx = all_cols.index(date_suggestions[0]) if date_suggestions else 0
307
 
308
- date_col = st.selectbox("Date column", all_cols, index=default_date_idx, key="sidebar_date_col")
 
 
309
 
310
  remaining = [c for c in all_cols if c != date_col]
311
  default_y = [c for c in numeric_suggestions if c != date_col]
312
- y_cols = st.multiselect(
313
- "Value column(s)",
314
- remaining,
315
- default=default_y[:4] if default_y else [],
316
- key="sidebar_y_cols",
317
- )
318
 
319
  st.session_state.date_col = date_col
320
  st.session_state.y_cols = y_cols
@@ -353,7 +352,6 @@ with st.sidebar:
353
  # Frequency override
354
  freq_override = st.text_input(
355
  "Override frequency label (optional)",
356
- value="",
357
  help="e.g. Daily, Weekly, Monthly, Quarterly, Yearly",
358
  key="sidebar_freq_override",
359
  )
@@ -646,12 +644,13 @@ with tab_few:
646
  else:
647
  st.subheader("Panel Plot (Small Multiples)")
648
 
649
- panel_cols = st.multiselect(
650
- "Columns to plot",
651
- y_cols,
652
- default=y_cols[:4],
653
- key="panel_cols",
654
- )
 
655
 
656
  if panel_cols:
657
  pc1, pc2 = st.columns(2)
@@ -660,7 +659,9 @@ with tab_few:
660
  "Chart type", ["line", "bar"], key="panel_chart"
661
  )
662
  with pc2:
663
- shared_y = st.checkbox("Shared Y axis", value=True, key="panel_shared")
 
 
664
 
665
  palette_name_b = st.selectbox("Color palette", _PALETTE_NAMES, key="pal_b")
666
  palette_b = get_palette_colors(palette_name_b, len(panel_cols))
@@ -711,12 +712,13 @@ with tab_many:
711
  else:
712
  st.subheader("Spaghetti Plot")
713
 
714
- spag_cols = st.multiselect(
715
- "Columns to include",
716
- y_cols,
717
- default=y_cols,
718
- key="spag_cols",
719
- )
 
720
 
721
  if spag_cols:
722
  sc1, sc2, sc3 = st.columns(3)
@@ -733,7 +735,7 @@ with tab_many:
733
  )
734
  highlight_col = highlight if highlight != "(none)" else None
735
 
736
- show_median = st.checkbox("Show Median + IQR band", value=False, key="spag_median")
737
 
738
  palette_name_c = st.selectbox("Color palette", _PALETTE_NAMES, key="pal_c")
739
  palette_c = get_palette_colors(palette_name_c, len(spag_cols))
 
305
  all_cols = list(raw_df.columns)
306
  default_date_idx = all_cols.index(date_suggestions[0]) if date_suggestions else 0
307
 
308
+ if "sidebar_date_col" not in st.session_state:
309
+ st.session_state["sidebar_date_col"] = all_cols[default_date_idx]
310
+ date_col = st.selectbox("Date column", all_cols, key="sidebar_date_col")
311
 
312
  remaining = [c for c in all_cols if c != date_col]
313
  default_y = [c for c in numeric_suggestions if c != date_col]
314
+ if "sidebar_y_cols" not in st.session_state:
315
+ st.session_state["sidebar_y_cols"] = default_y[:4] if default_y else []
316
+ y_cols = st.multiselect("Value column(s)", remaining, key="sidebar_y_cols")
 
 
 
317
 
318
  st.session_state.date_col = date_col
319
  st.session_state.y_cols = y_cols
 
352
  # Frequency override
353
  freq_override = st.text_input(
354
  "Override frequency label (optional)",
 
355
  help="e.g. Daily, Weekly, Monthly, Quarterly, Yearly",
356
  key="sidebar_freq_override",
357
  )
 
644
  else:
645
  st.subheader("Panel Plot (Small Multiples)")
646
 
647
+ if "panel_cols" not in st.session_state:
648
+ st.session_state["panel_cols"] = y_cols[:4]
649
+ else:
650
+ st.session_state["panel_cols"] = [
651
+ c for c in st.session_state["panel_cols"] if c in y_cols
652
+ ]
653
+ panel_cols = st.multiselect("Columns to plot", y_cols, key="panel_cols")
654
 
655
  if panel_cols:
656
  pc1, pc2 = st.columns(2)
 
659
  "Chart type", ["line", "bar"], key="panel_chart"
660
  )
661
  with pc2:
662
+ if "panel_shared" not in st.session_state:
663
+ st.session_state["panel_shared"] = True
664
+ shared_y = st.checkbox("Shared Y axis", key="panel_shared")
665
 
666
  palette_name_b = st.selectbox("Color palette", _PALETTE_NAMES, key="pal_b")
667
  palette_b = get_palette_colors(palette_name_b, len(panel_cols))
 
712
  else:
713
  st.subheader("Spaghetti Plot")
714
 
715
+ if "spag_cols" not in st.session_state:
716
+ st.session_state["spag_cols"] = list(y_cols)
717
+ else:
718
+ st.session_state["spag_cols"] = [
719
+ c for c in st.session_state["spag_cols"] if c in y_cols
720
+ ]
721
+ spag_cols = st.multiselect("Columns to include", y_cols, key="spag_cols")
722
 
723
  if spag_cols:
724
  sc1, sc2, sc3 = st.columns(3)
 
735
  )
736
  highlight_col = highlight if highlight != "(none)" else None
737
 
738
+ show_median = st.checkbox("Show Median + IQR band", key="spag_median")
739
 
740
  palette_name_c = st.selectbox("Color palette", _PALETTE_NAMES, key="pal_c")
741
  palette_c = get_palette_colors(palette_name_c, len(spag_cols))