James McCool commited on
Commit
c47e22d
·
1 Parent(s): fb140dc

Improve pagination and loading experience in pitcher tab of Streamlit app

Browse files

- Introduced pagination controls ('Previous' and 'Next' buttons) to enhance data navigation within the displayed frame.
- Adjusted the loading spinner implementation for league baseline data to improve user experience during data retrieval.
- Streamlined the display logic to ensure consistent presentation of data based on user selections.

Files changed (1) hide show
  1. src/streamlit_app.py +17 -5
src/streamlit_app.py CHANGED
@@ -171,14 +171,26 @@ with pitcher_tab:
171
  disp_raw = disp_raw[['Player', 'PA', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeoutper', 'Strikeouts', 'Walkper', 'Walks', 'xBA', 'xSLG', 'xwOBA', 'BABIP', 'AVG', 'FB%', 'True_AVG', 'xHits', 'xHRs', 'xHR/PA', 'HWSr']]
172
 
173
  st.session_state['sp_disp_frame'] = disp_raw
 
174
  sp_disp_container = st.container(border = True)
175
  sp_disp_container = sp_disp_container.empty()
176
 
177
- with sp_disp_container:
178
- if table_var_sp in (['League Aggregate Baselines', 'League Short Term Baselines', 'League Long Term Baselines']):
179
- with st.spinner("Full league baselines can take some time to load"):
180
- time.sleep(7)
181
- st.dataframe(st.session_state['sp_disp_frame'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn_r').format(precision=2), height = 750, use_container_width = True, hide_index = True)
 
 
 
 
 
 
 
 
 
 
 
182
 
183
  with hitter_tab:
184
  with st.container(border = True):
 
171
  disp_raw = disp_raw[['Player', 'PA', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeoutper', 'Strikeouts', 'Walkper', 'Walks', 'xBA', 'xSLG', 'xwOBA', 'BABIP', 'AVG', 'FB%', 'True_AVG', 'xHits', 'xHRs', 'xHR/PA', 'HWSr']]
172
 
173
  st.session_state['sp_disp_frame'] = disp_raw
174
+ page_var = len(st.session_state['sp_disp_frame']) / 2
175
  sp_disp_container = st.container(border = True)
176
  sp_disp_container = sp_disp_container.empty()
177
 
178
+ if table_var_sp in (['League Aggregate Baselines', 'League Short Term Baselines', 'League Long Term Baselines']):
179
+
180
+ with st.spinner("Full league baselines can take some time to load"):
181
+ time.sleep(7)
182
+ with sp_disp_container:
183
+ st.dataframe(st.session_state['sp_disp_frame'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn_r').format(precision=2), height = 500, use_container_width = True, hide_index = True)
184
+ col1, col2, col3, col4 = st.columns(4)
185
+ with col1:
186
+ if st.button('Previous'):
187
+ st.session_state['sp_disp_frame'] = st.session_state['sp_disp_frame'].iloc[:page_var]
188
+ with col4:
189
+ if st.button('Next'):
190
+ st.session_state['sp_disp_frame'] = st.session_state['sp_disp_frame'].iloc[page_var:]
191
+ else:
192
+ with sp_disp_container:
193
+ st.dataframe(st.session_state['sp_disp_frame'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn_r').format(precision=2), height = 500, use_container_width = True, hide_index = True)
194
 
195
  with hitter_tab:
196
  with st.container(border = True):