James McCool commited on
Commit
94b6cea
·
1 Parent(s): d7f15e0

Refactor player selection logic in Handbuilder tab of app.py by removing the "Clear All Selections" button and simplifying the state management. Introduce a "Clear Data" button to reset selections, enhancing user experience and interactivity.

Browse files
Files changed (1) hide show
  1. app.py +5 -16
app.py CHANGED
@@ -802,27 +802,15 @@ with tab3:
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,8 +822,6 @@ with tab4:
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,3 +835,6 @@ with tab4:
849
  height=300,
850
  hide_index=True
851
  )
 
 
 
 
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 # Add a checkbox column
 
 
 
 
 
 
 
 
 
808
 
809
  col1, col2 = st.columns([1, 2])
810
  with col2:
811
  st.subheader("Player Select")
812
  edited_df = st.data_editor(
813
+ player_select_df,
814
  column_config={
815
  "Select": st.column_config.CheckboxColumn(
816
  "Select",
 
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
  height=300,
836
  hide_index=True
837
  )
838
+
839
+ if st.button("Clear Data", key='clear_handbuild'):
840
+ player_select_df['Select'] = False