Spaces:
Running
Running
James McCool
commited on
Commit
·
6362b12
1
Parent(s):
cd79eb2
Refactor player selection logic in Handbuilder tab of app.py to streamline DataFrame handling and improve user experience by ensuring fresh data on each rerun, while maintaining lineup display functionality.
Browse files
app.py
CHANGED
@@ -802,45 +802,15 @@ with tab3:
|
|
802 |
with tab4:
|
803 |
st.header("Handbuilder")
|
804 |
|
805 |
-
#
|
806 |
-
|
807 |
-
|
808 |
-
st.session_state.handbuilder_select['Select'] = False
|
809 |
-
|
810 |
-
# Use the session state DataFrame as the source
|
811 |
-
edited_df = st.data_editor(
|
812 |
-
st.session_state.handbuilder_select,
|
813 |
-
column_config={
|
814 |
-
"Select": st.column_config.CheckboxColumn(
|
815 |
-
"Select",
|
816 |
-
help="Check to add player to lineup",
|
817 |
-
default=False
|
818 |
-
)
|
819 |
-
},
|
820 |
-
use_container_width=True,
|
821 |
-
hide_index=True,
|
822 |
-
key="handbuilder_editor"
|
823 |
-
)
|
824 |
-
|
825 |
-
# Update session state only if there are changes
|
826 |
-
if not edited_df.equals(st.session_state.handbuilder_select):
|
827 |
-
st.session_state.handbuilder_select = edited_df
|
828 |
-
|
829 |
-
# Filter selected players for the lineup
|
830 |
-
selected_players = st.session_state.handbuilder_select[st.session_state.handbuilder_select['Select'] == True]
|
831 |
|
832 |
col1, col2 = st.columns([1, 2])
|
833 |
-
with col1:
|
834 |
-
st.subheader("Lineup")
|
835 |
-
st.dataframe(
|
836 |
-
selected_players.drop(columns=['Select']),
|
837 |
-
use_container_width=True,
|
838 |
-
height=500
|
839 |
-
)
|
840 |
with col2:
|
841 |
st.subheader("Player Select")
|
842 |
-
st.data_editor(
|
843 |
-
|
844 |
column_config={
|
845 |
"Select": st.column_config.CheckboxColumn(
|
846 |
"Select",
|
@@ -850,5 +820,16 @@ with tab4:
|
|
850 |
},
|
851 |
use_container_width=True,
|
852 |
hide_index=True,
|
853 |
-
key="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
854 |
)
|
|
|
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', 'Ceiling', '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",
|
|
|
820 |
},
|
821 |
use_container_width=True,
|
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]
|
828 |
+
|
829 |
+
with col1:
|
830 |
+
st.subheader("Lineup")
|
831 |
+
st.dataframe(
|
832 |
+
selected_players.drop(columns=['Select']),
|
833 |
+
use_container_width=True,
|
834 |
+
height=500
|
835 |
)
|