James McCool
commited on
Commit
·
e02d027
1
Parent(s):
1ced724
Refactor session state management in Streamlit app by simplifying key clearance logic and removing unnecessary debug output. This change enhances code clarity and maintains essential session data for improved user experience.
Browse files- src/streamlit_app.py +2 -14
src/streamlit_app.py
CHANGED
|
@@ -8,18 +8,9 @@ print(f"Streamlit version: {st.__version__}")
|
|
| 8 |
|
| 9 |
maintained_keys = ['tab_selector', 'site_selectbox', 'view_selectbox']
|
| 10 |
|
| 11 |
-
|
| 12 |
-
all_keys = list(st.session_state.keys())
|
| 13 |
-
cleared_keys = []
|
| 14 |
-
|
| 15 |
-
for key in all_keys:
|
| 16 |
if key not in maintained_keys:
|
| 17 |
del st.session_state[key]
|
| 18 |
-
cleared_keys.append(key)
|
| 19 |
-
|
| 20 |
-
# Debug: Print what was cleared (you can remove this later)
|
| 21 |
-
if cleared_keys:
|
| 22 |
-
print(f"Cleared keys: {cleared_keys}")
|
| 23 |
|
| 24 |
st.set_page_config(layout="wide")
|
| 25 |
|
|
@@ -423,8 +414,6 @@ if selected_tab == 'Handbuilder':
|
|
| 423 |
# --- LINEUP STATE ---
|
| 424 |
if 'handbuilder_lineup' not in st.session_state:
|
| 425 |
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own'])
|
| 426 |
-
if 'handbuilder_select_key' not in st.session_state:
|
| 427 |
-
st.session_state['handbuilder_select_key'] = 0
|
| 428 |
|
| 429 |
# Count positions in the current lineup
|
| 430 |
lineup = st.session_state['handbuilder_lineup']
|
|
@@ -575,7 +564,7 @@ if selected_tab == 'Handbuilder':
|
|
| 575 |
player_select_df.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Salary', 'Own']).format(precision=2),
|
| 576 |
on_select="rerun",
|
| 577 |
selection_mode=["single-row"],
|
| 578 |
-
key=
|
| 579 |
height=500,
|
| 580 |
hide_index=True
|
| 581 |
)
|
|
@@ -606,7 +595,6 @@ if selected_tab == 'Handbuilder':
|
|
| 606 |
[st.session_state['handbuilder_lineup'], player_row[['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own', 'Slot']]],
|
| 607 |
ignore_index=True
|
| 608 |
)
|
| 609 |
-
st.session_state['handbuilder_select_key'] += 1
|
| 610 |
|
| 611 |
|
| 612 |
with handbuilder_lineup_build_column:
|
|
|
|
| 8 |
|
| 9 |
maintained_keys = ['tab_selector', 'site_selectbox', 'view_selectbox']
|
| 10 |
|
| 11 |
+
for key in list(st.session_state.keys()):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if key not in maintained_keys:
|
| 13 |
del st.session_state[key]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
st.set_page_config(layout="wide")
|
| 16 |
|
|
|
|
| 414 |
# --- LINEUP STATE ---
|
| 415 |
if 'handbuilder_lineup' not in st.session_state:
|
| 416 |
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own'])
|
|
|
|
|
|
|
| 417 |
|
| 418 |
# Count positions in the current lineup
|
| 419 |
lineup = st.session_state['handbuilder_lineup']
|
|
|
|
| 564 |
player_select_df.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Salary', 'Own']).format(precision=2),
|
| 565 |
on_select="rerun",
|
| 566 |
selection_mode=["single-row"],
|
| 567 |
+
key="player_select_dataframe",
|
| 568 |
height=500,
|
| 569 |
hide_index=True
|
| 570 |
)
|
|
|
|
| 595 |
[st.session_state['handbuilder_lineup'], player_row[['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own', 'Slot']]],
|
| 596 |
ignore_index=True
|
| 597 |
)
|
|
|
|
| 598 |
|
| 599 |
|
| 600 |
with handbuilder_lineup_build_column:
|