Spaces:
Running
Running
James McCool
commited on
Commit
·
263e733
1
Parent(s):
4263647
Enhance player selection state management in Handbuilder tab of app.py by initializing and maintaining a session state for selected indices. Implement logic to handle out-of-range selections and update the display based on current selections, improving user experience and selection accuracy.
Browse files
app.py
CHANGED
@@ -807,6 +807,7 @@ with tab4:
|
|
807 |
|
808 |
if st.button("Clear Data", key='clear_handbuild'):
|
809 |
st.session_state.handbuilder_editor_key += 1
|
|
|
810 |
st.rerun()
|
811 |
|
812 |
# --- TEAM FILTER UI ---
|
@@ -831,6 +832,16 @@ with tab4:
|
|
831 |
else:
|
832 |
player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', 'Order', 'Hand', 'Own%']].copy()
|
833 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
834 |
col1, col2 = st.columns([1, 2])
|
835 |
with col2:
|
836 |
st.subheader("Player Select")
|
@@ -838,12 +849,16 @@ with tab4:
|
|
838 |
player_select_df,
|
839 |
key=f"handbuilder_editor_{st.session_state.handbuilder_editor_key}",
|
840 |
on_select="rerun",
|
841 |
-
selection_mode=["multi-row"]
|
|
|
842 |
)
|
843 |
|
|
|
|
|
|
|
|
|
844 |
# Get selected rows
|
845 |
-
|
846 |
-
select_players_disp = player_select_df.iloc[selected_indices][['Player', 'Team', 'Salary', 'Median', 'Own%']]
|
847 |
|
848 |
with col1:
|
849 |
st.subheader("Lineup")
|
|
|
807 |
|
808 |
if st.button("Clear Data", key='clear_handbuild'):
|
809 |
st.session_state.handbuilder_editor_key += 1
|
810 |
+
st.session_state.handbuilder_selected_indices = []
|
811 |
st.rerun()
|
812 |
|
813 |
# --- TEAM FILTER UI ---
|
|
|
832 |
else:
|
833 |
player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', 'Order', 'Hand', 'Own%']].copy()
|
834 |
|
835 |
+
# --- ROW SELECTION STATE ---
|
836 |
+
# Map previous selection to the new filtered DataFrame
|
837 |
+
if 'handbuilder_selected_indices' not in st.session_state:
|
838 |
+
st.session_state.handbuilder_selected_indices = []
|
839 |
+
|
840 |
+
# Remove indices that are out of range (in case the player pool shrinks)
|
841 |
+
st.session_state.handbuilder_selected_indices = [
|
842 |
+
i for i in st.session_state.handbuilder_selected_indices if i < len(player_select_df)
|
843 |
+
]
|
844 |
+
|
845 |
col1, col2 = st.columns([1, 2])
|
846 |
with col2:
|
847 |
st.subheader("Player Select")
|
|
|
849 |
player_select_df,
|
850 |
key=f"handbuilder_editor_{st.session_state.handbuilder_editor_key}",
|
851 |
on_select="rerun",
|
852 |
+
selection_mode=["multi-row"],
|
853 |
+
selected_rows=st.session_state.handbuilder_selected_indices
|
854 |
)
|
855 |
|
856 |
+
# Update session state with new selection if changed
|
857 |
+
if event and "rows" in event.selection:
|
858 |
+
st.session_state.handbuilder_selected_indices = event.selection["rows"]
|
859 |
+
|
860 |
# Get selected rows
|
861 |
+
select_players_disp = player_select_df.iloc[st.session_state.handbuilder_selected_indices][['Player', 'Team', 'Salary', 'Median', 'Own%']]
|
|
|
862 |
|
863 |
with col1:
|
864 |
st.subheader("Lineup")
|