James McCool commited on
Commit
98e23b6
·
1 Parent(s): 6cf69ca

Enhance player selection functionality in Handbuilder tab of Streamlit app by introducing a dynamic dataframe key for improved state management and ensuring selections are cleared effectively upon lineup reset.

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +8 -3
src/streamlit_app.py CHANGED
@@ -616,11 +616,13 @@ if selected_tab == 'Handbuilder':
616
  handbuilder_lineup_build_column, handbuilder_player_select_column = st.columns([1, 2])
617
  with handbuilder_player_select_column:
618
  st.subheader("Player Select")
 
 
619
  event = st.dataframe(
620
  st.session_state['player_select_df'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Salary', 'Own']).format(precision=2),
621
  on_select="rerun",
622
- selection_mode="multi-row", # Changed to multiple selection
623
- key="player_select_dataframe",
624
  height=500,
625
  hide_index=True
626
  )
@@ -787,8 +789,11 @@ if selected_tab == 'Handbuilder':
787
  clear_col, save_col, export_col, clear_saved_col, blank_col = st.columns([2, 2, 2, 2, 12])
788
  with clear_col:
789
  if st.button("Clear Lineup", key='clear_lineup_button'):
790
- st.session_state['previous_player_selection'] = []
791
  st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own', 'Slot'])
 
 
 
 
792
  st.rerun()
793
  with save_col:
794
  if st.button("Save Lineup", key='save_lineup_button'):
 
616
  handbuilder_lineup_build_column, handbuilder_player_select_column = st.columns([1, 2])
617
  with handbuilder_player_select_column:
618
  st.subheader("Player Select")
619
+ dataframe_key = f"player_select_dataframe_{st.session_state.get('dataframe_key_counter', 0)}"
620
+
621
  event = st.dataframe(
622
  st.session_state['player_select_df'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Salary', 'Own']).format(precision=2),
623
  on_select="rerun",
624
+ selection_mode="multi-row",
625
+ key=dataframe_key,
626
  height=500,
627
  hide_index=True
628
  )
 
789
  clear_col, save_col, export_col, clear_saved_col, blank_col = st.columns([2, 2, 2, 2, 12])
790
  with clear_col:
791
  if st.button("Clear Lineup", key='clear_lineup_button'):
 
792
  st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own', 'Slot'])
793
+ # Clear the dataframe selections by resetting the previous selection state
794
+ st.session_state['previous_player_selection'] = []
795
+ # Force dataframe to re-render with new key to clear selections
796
+ st.session_state['dataframe_key_counter'] = st.session_state.get('dataframe_key_counter', 0) + 1
797
  st.rerun()
798
  with save_col:
799
  if st.button("Save Lineup", key='save_lineup_button'):