Spaces:
Running
Running
James McCool
commited on
Commit
·
d7f15e0
1
Parent(s):
e9c95d8
Implement "Clear All Selections" button in Handbuilder tab of app.py to reset player selections, enhancing user interactivity. Update session state management to preserve user selections across reruns, improving overall functionality.
Browse files
app.py
CHANGED
@@ -802,15 +802,27 @@ with tab3:
|
|
802 |
with tab4:
|
803 |
st.header("Handbuilder")
|
804 |
|
|
|
|
|
|
|
805 |
# Prepare the player selection DataFrame (fresh on every rerun)
|
806 |
player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', 'Order', 'Hand', 'Own%']].copy()
|
807 |
-
player_select_df['Select'] = False #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
808 |
|
809 |
col1, col2 = st.columns([1, 2])
|
810 |
with col2:
|
811 |
st.subheader("Player Select")
|
812 |
edited_df = st.data_editor(
|
813 |
-
|
814 |
column_config={
|
815 |
"Select": st.column_config.CheckboxColumn(
|
816 |
"Select",
|
@@ -822,6 +834,8 @@ with tab4:
|
|
822 |
hide_index=True,
|
823 |
key="handbuilder_editor"
|
824 |
)
|
|
|
|
|
825 |
|
826 |
# Filter selected players for the lineup
|
827 |
selected_players = edited_df[edited_df['Select'] == True]
|
@@ -835,12 +849,3 @@ with tab4:
|
|
835 |
height=300,
|
836 |
hide_index=True
|
837 |
)
|
838 |
-
|
839 |
-
if st.button("Clear Data", key='clear_handbuild'):
|
840 |
-
player_select_df['Select'] = False
|
841 |
-
edited_df = st.data_editor(
|
842 |
-
player_select_df,
|
843 |
-
use_container_width=True,
|
844 |
-
hide_index=True,
|
845 |
-
key="handbuilder_editor"
|
846 |
-
)
|
|
|
802 |
with tab4:
|
803 |
st.header("Handbuilder")
|
804 |
|
805 |
+
# Add a button to clear all checks
|
806 |
+
clear = st.button("Clear All Selections", key='clear_handbuild')
|
807 |
+
|
808 |
# Prepare the player selection DataFrame (fresh on every rerun)
|
809 |
player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', 'Order', 'Hand', 'Own%']].copy()
|
810 |
+
player_select_df['Select'] = False # Default: all unchecked
|
811 |
+
|
812 |
+
# If the clear button is pressed, keep all unchecked
|
813 |
+
# Otherwise, try to preserve the user's current selection
|
814 |
+
if 'handbuilder_editor_data' not in st.session_state or clear:
|
815 |
+
# On first load or when clear is pressed, start fresh (all unchecked)
|
816 |
+
edited_df = player_select_df
|
817 |
+
else:
|
818 |
+
# Otherwise, use the last edited data
|
819 |
+
edited_df = pd.DataFrame(st.session_state.handbuilder_editor_data)
|
820 |
|
821 |
col1, col2 = st.columns([1, 2])
|
822 |
with col2:
|
823 |
st.subheader("Player Select")
|
824 |
edited_df = st.data_editor(
|
825 |
+
edited_df,
|
826 |
column_config={
|
827 |
"Select": st.column_config.CheckboxColumn(
|
828 |
"Select",
|
|
|
834 |
hide_index=True,
|
835 |
key="handbuilder_editor"
|
836 |
)
|
837 |
+
# Save the current state for next rerun
|
838 |
+
st.session_state.handbuilder_editor_data = edited_df
|
839 |
|
840 |
# Filter selected players for the lineup
|
841 |
selected_players = edited_df[edited_df['Select'] == True]
|
|
|
849 |
height=300,
|
850 |
hide_index=True
|
851 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|