James McCool commited on
Commit
94b689a
·
1 Parent(s): 1eeb961

Add pagination to contest data display in app.py

Browse files

- Implemented pagination controls for the contest dataframe, allowing users to navigate through large datasets more easily.
- Initialized session state for current page tracking and calculated total pages based on the number of rows.
- Updated the dataframe display to show only the data for the current page, enhancing user experience and data visualization.

Files changed (1) hide show
  1. app.py +27 -2
app.py CHANGED
@@ -135,9 +135,34 @@ with tab2:
135
  )
136
 
137
  with col2:
138
- # Display the paginated dataframe first
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  st.dataframe(
140
- st.session_state['Contest'].style
141
  .background_gradient(axis=0)
142
  .background_gradient(cmap='RdYlGn')
143
  .format(precision=2),
 
135
  )
136
 
137
  with col2:
138
+
139
+ # Initialize pagination in session state if not exists
140
+ if 'current_page' not in st.session_state:
141
+ st.session_state.current_page = 0
142
+
143
+ # Calculate total pages
144
+ rows_per_page = 500
145
+ total_rows = len(st.session_state['Contest'])
146
+ total_pages = (total_rows + rows_per_page - 1) // rows_per_page
147
+
148
+ # Create pagination controls
149
+ col1, col2, col3 = st.columns([1, 2, 1])
150
+ with col1:
151
+ if st.button("Previous Page") and st.session_state.current_page > 0:
152
+ st.session_state.current_page -= 1
153
+ with col2:
154
+ st.write(f"Page {st.session_state.current_page + 1} of {total_pages}")
155
+ with col3:
156
+ if st.button("Next Page") and st.session_state.current_page < total_pages - 1:
157
+ st.session_state.current_page += 1
158
+
159
+ # Calculate start and end indices for current page
160
+ start_idx = st.session_state.current_page * rows_per_page
161
+ end_idx = min((st.session_state.current_page + 1) * rows_per_page, total_rows)
162
+
163
+ # Display the paginated dataframe
164
  st.dataframe(
165
+ st.session_state['Contest'].iloc[start_idx:end_idx].style
166
  .background_gradient(axis=0)
167
  .background_gradient(cmap='RdYlGn')
168
  .format(precision=2),