James McCool
commited on
Commit
·
6c2a3a2
1
Parent(s):
df09c16
Refactor data clearing functionality and enhance pagination display in app.py
Browse files- Moved the 'Clear data' button to the filters section for better accessibility and user experience.
- Added a new section to display the paginated dataframe with improved styling and formatting for clarity.
- Ensured session state management remains intact while providing a clear option for users to reset data.
app.py
CHANGED
|
@@ -82,8 +82,6 @@ with tab1:
|
|
| 82 |
st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'] = find_name_mismatches(st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'])
|
| 83 |
|
| 84 |
with tab2:
|
| 85 |
-
if st.button('Clear data', key='reset3'):
|
| 86 |
-
st.session_state.clear()
|
| 87 |
if 'Contest' in st.session_state and 'projections_df' in st.session_state:
|
| 88 |
col1, col2 = st.columns([1, 8])
|
| 89 |
excluded_cols = ['BaseName', 'EntryCount']
|
|
@@ -106,6 +104,8 @@ with tab2:
|
|
| 106 |
|
| 107 |
with col1:
|
| 108 |
with st.expander("Info and filters"):
|
|
|
|
|
|
|
| 109 |
with st.form(key='filter_form'):
|
| 110 |
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
| 111 |
entry_parse_var = st.selectbox("Do you want to view a specific player(s) or a group of players?", ['All', 'Specific'])
|
|
@@ -238,6 +238,16 @@ with tab2:
|
|
| 238 |
format(formatter='{:.2%}', subset=st.session_state['stack_frame'].select_dtypes(include=['number']).columns),
|
| 239 |
hide_index=True)
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
# Initialize pagination in session state if not exists
|
| 243 |
if 'current_page' not in st.session_state:
|
|
@@ -262,14 +272,3 @@ with tab2:
|
|
| 262 |
# Calculate start and end indices for current page
|
| 263 |
start_idx = st.session_state.current_page * rows_per_page
|
| 264 |
end_idx = min((st.session_state.current_page + 1) * rows_per_page, total_rows)
|
| 265 |
-
|
| 266 |
-
# Display the paginated dataframe
|
| 267 |
-
st.dataframe(
|
| 268 |
-
working_df.iloc[start_idx:end_idx].style
|
| 269 |
-
.background_gradient(axis=0)
|
| 270 |
-
.background_gradient(cmap='RdYlGn')
|
| 271 |
-
.format(precision=2),
|
| 272 |
-
height=1000,
|
| 273 |
-
use_container_width=True,
|
| 274 |
-
hide_index=True
|
| 275 |
-
)
|
|
|
|
| 82 |
st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'] = find_name_mismatches(st.session_state['Contest'], st.session_state['projections_df'], st.session_state['ownership_dict'], st.session_state['actual_dict'])
|
| 83 |
|
| 84 |
with tab2:
|
|
|
|
|
|
|
| 85 |
if 'Contest' in st.session_state and 'projections_df' in st.session_state:
|
| 86 |
col1, col2 = st.columns([1, 8])
|
| 87 |
excluded_cols = ['BaseName', 'EntryCount']
|
|
|
|
| 104 |
|
| 105 |
with col1:
|
| 106 |
with st.expander("Info and filters"):
|
| 107 |
+
if st.button('Clear data', key='reset3'):
|
| 108 |
+
st.session_state.clear()
|
| 109 |
with st.form(key='filter_form'):
|
| 110 |
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
| 111 |
entry_parse_var = st.selectbox("Do you want to view a specific player(s) or a group of players?", ['All', 'Specific'])
|
|
|
|
| 238 |
format(formatter='{:.2%}', subset=st.session_state['stack_frame'].select_dtypes(include=['number']).columns),
|
| 239 |
hide_index=True)
|
| 240 |
|
| 241 |
+
# Display the paginated dataframe
|
| 242 |
+
st.dataframe(
|
| 243 |
+
working_df.iloc[start_idx:end_idx].style
|
| 244 |
+
.background_gradient(axis=0)
|
| 245 |
+
.background_gradient(cmap='RdYlGn')
|
| 246 |
+
.format(precision=2),
|
| 247 |
+
height=1000,
|
| 248 |
+
use_container_width=True,
|
| 249 |
+
hide_index=True
|
| 250 |
+
)
|
| 251 |
|
| 252 |
# Initialize pagination in session state if not exists
|
| 253 |
if 'current_page' not in st.session_state:
|
|
|
|
| 272 |
# Calculate start and end indices for current page
|
| 273 |
start_idx = st.session_state.current_page * rows_per_page
|
| 274 |
end_idx = min((st.session_state.current_page + 1) * rows_per_page, total_rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|