James McCool commited on
Commit
0720ad1
·
1 Parent(s): 34460c9

Implement single-row selection for lineup removal in Handbuilder tab of app.py, allowing users to easily remove players from the lineup. Update DataFrame display logic to enhance user interaction and streamline lineup management.

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -900,13 +900,11 @@ with tab4:
900
  lineup_slots = ['SP', 'SP', 'C', '1B', '2B', '3B', 'SS', 'OF', 'OF', 'OF']
901
  display_columns = ['Slot', 'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', 'Own%']
902
 
903
- # Prepare a DataFrame for display in the explicit order
904
  filled_lineup = st.session_state['handbuilder_lineup']
905
  display_rows = []
906
  used_indices = set()
907
 
908
  for slot in lineup_slots:
909
- # Find the first player in the lineup who fills this slot and hasn't been used yet
910
  match = filled_lineup[(filled_lineup['Slot'] == slot) & (~filled_lineup.index.isin(used_indices))]
911
  if not match.empty:
912
  row = match.iloc[0]
@@ -922,7 +920,6 @@ with tab4:
922
  'Own%': row['Own%']
923
  })
924
  else:
925
- # Blank row for unfilled slot
926
  display_rows.append({
927
  'Slot': slot,
928
  'Player': '',
@@ -936,13 +933,27 @@ with tab4:
936
 
937
  lineup_display_df = pd.DataFrame(display_rows, columns=display_columns)
938
 
939
- st.dataframe(
 
940
  lineup_display_df,
941
- use_container_width=True,
 
 
942
  height=445,
943
  hide_index=True
944
  )
945
 
 
 
 
 
 
 
 
 
 
 
 
946
  # --- SUMMARY ROW ---
947
  if not filled_lineup.empty:
948
  total_salary = filled_lineup['Salary'].sum()
 
900
  lineup_slots = ['SP', 'SP', 'C', '1B', '2B', '3B', 'SS', 'OF', 'OF', 'OF']
901
  display_columns = ['Slot', 'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', 'Own%']
902
 
 
903
  filled_lineup = st.session_state['handbuilder_lineup']
904
  display_rows = []
905
  used_indices = set()
906
 
907
  for slot in lineup_slots:
 
908
  match = filled_lineup[(filled_lineup['Slot'] == slot) & (~filled_lineup.index.isin(used_indices))]
909
  if not match.empty:
910
  row = match.iloc[0]
 
920
  'Own%': row['Own%']
921
  })
922
  else:
 
923
  display_rows.append({
924
  'Slot': slot,
925
  'Player': '',
 
933
 
934
  lineup_display_df = pd.DataFrame(display_rows, columns=display_columns)
935
 
936
+ # Show the lineup table with single-row selection for removal
937
+ event_remove = st.dataframe(
938
  lineup_display_df,
939
+ on_select="rerun",
940
+ selection_mode=["single-row"],
941
+ key="lineup_remove",
942
  height=445,
943
  hide_index=True
944
  )
945
 
946
+ # If a row is selected and not blank, remove that player from the lineup
947
+ if event_remove and "rows" in event_remove.selection and len(event_remove.selection["rows"]) > 0:
948
+ idx = event_remove.selection["rows"][0]
949
+ player_to_remove = lineup_display_df.iloc[idx]['Player']
950
+ slot_to_remove = lineup_display_df.iloc[idx]['Slot']
951
+ if player_to_remove: # Only remove if not blank
952
+ st.session_state['handbuilder_lineup'] = filled_lineup[
953
+ ~((filled_lineup['Player'] == player_to_remove) & (filled_lineup['Slot'] == slot_to_remove))
954
+ ]
955
+ st.rerun()
956
+
957
  # --- SUMMARY ROW ---
958
  if not filled_lineup.empty:
959
  total_salary = filled_lineup['Salary'].sum()