James McCool
commited on
Commit
·
8e02398
1
Parent(s):
81184ae
Refine position selection in app.py for improved user experience
Browse files- Replaced the radio button for position selection with a select box, allowing users to choose between viewing all positions or specific ones.
- Updated the filtering logic to accommodate the new selection method, enhancing the clarity and relevance of displayed player data.
app.py
CHANGED
@@ -211,20 +211,21 @@ with tab2:
|
|
211 |
with tab1:
|
212 |
col1, col2 = st.columns(2)
|
213 |
with col1:
|
214 |
-
pos_var = st.
|
215 |
with col2:
|
216 |
-
if pos_var == '
|
217 |
-
|
218 |
else:
|
219 |
-
|
220 |
|
221 |
if entry_parse_var == 'All':
|
222 |
st.session_state['player_frame'] = create_player_exposures(working_df, player_columns)
|
223 |
hold_frame = st.session_state['player_frame'].copy()
|
224 |
hold_frame['Pos'] = hold_frame['Player'].map(map_dict['pos_map'])
|
225 |
st.session_state['player_frame'].insert(1, 'Pos', hold_frame['Pos'])
|
226 |
-
|
227 |
-
|
|
|
228 |
st.dataframe(st.session_state['player_frame'].
|
229 |
sort_values(by='Exposure Overall', ascending=False).
|
230 |
style.background_gradient(cmap='RdYlGn').
|
@@ -235,8 +236,9 @@ with tab2:
|
|
235 |
hold_frame = st.session_state['player_frame'].copy()
|
236 |
hold_frame['Pos'] = hold_frame['Player'].map(map_dict['pos_map'])
|
237 |
st.session_state['player_frame'].insert(1, 'Pos', hold_frame['Pos'])
|
238 |
-
|
239 |
-
|
|
|
240 |
st.dataframe(st.session_state['player_frame'].
|
241 |
sort_values(by='Exposure Overall', ascending=False).
|
242 |
style.background_gradient(cmap='RdYlGn').
|
|
|
211 |
with tab1:
|
212 |
col1, col2 = st.columns(2)
|
213 |
with col1:
|
214 |
+
pos_var = st.selectbox("Which position(s) would you like to view?", ['All', 'Specific'], key='pos_var')
|
215 |
with col2:
|
216 |
+
if pos_var == 'Specific':
|
217 |
+
pos_select = st.multiselect("Select your position(s)", ['P', 'C', '1B', '2B', '3B', 'SS', 'OF'], key='pos_select')
|
218 |
else:
|
219 |
+
pos_select = None
|
220 |
|
221 |
if entry_parse_var == 'All':
|
222 |
st.session_state['player_frame'] = create_player_exposures(working_df, player_columns)
|
223 |
hold_frame = st.session_state['player_frame'].copy()
|
224 |
hold_frame['Pos'] = hold_frame['Player'].map(map_dict['pos_map'])
|
225 |
st.session_state['player_frame'].insert(1, 'Pos', hold_frame['Pos'])
|
226 |
+
if pos_select:
|
227 |
+
position_mask = st.session_state['player_frame']['Pos'].apply(lambda x: any(pos in x for pos in pos_select))
|
228 |
+
st.session_state['player_frame'] = st.session_state['player_frame'][position_mask]
|
229 |
st.dataframe(st.session_state['player_frame'].
|
230 |
sort_values(by='Exposure Overall', ascending=False).
|
231 |
style.background_gradient(cmap='RdYlGn').
|
|
|
236 |
hold_frame = st.session_state['player_frame'].copy()
|
237 |
hold_frame['Pos'] = hold_frame['Player'].map(map_dict['pos_map'])
|
238 |
st.session_state['player_frame'].insert(1, 'Pos', hold_frame['Pos'])
|
239 |
+
if pos_select:
|
240 |
+
position_mask = st.session_state['player_frame']['Pos'].apply(lambda x: any(pos in x for pos in pos_select))
|
241 |
+
st.session_state['player_frame'] = st.session_state['player_frame'][position_mask]
|
242 |
st.dataframe(st.session_state['player_frame'].
|
243 |
sort_values(by='Exposure Overall', ascending=False).
|
244 |
style.background_gradient(cmap='RdYlGn').
|