James McCool
commited on
Commit
·
d415f18
1
Parent(s):
99e552f
Implement user selection and pagination for duplication frame in app.py
Browse files- Added a form for users to select specific usage(s) to view in the duplication frame, enhancing user interactivity.
- Implemented pagination controls to navigate through the duplication frame, improving data accessibility and usability.
- Updated the duplication frame to reflect user selections and maintain clarity in data presentation.
app.py
CHANGED
|
@@ -442,13 +442,54 @@ with tab2:
|
|
| 442 |
st.dataframe(st.session_state['general_frame'].style.background_gradient(cmap='RdYlGn', axis=1).format(precision=2), hide_index=True)
|
| 443 |
|
| 444 |
with tab5:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
dupe_frame = working_df[['BaseName', 'EntryCount', 'dupes', 'uniques', 'under_5', 'under_10']]
|
| 446 |
dupe_frame['average_dupes'] = dupe_frame['dupes'].mean()
|
| 447 |
dupe_frame['uniques%'] = dupe_frame['uniques'] / dupe_frame['EntryCount']
|
| 448 |
dupe_frame['under_5%'] = dupe_frame['under_5'] / dupe_frame['EntryCount']
|
| 449 |
dupe_frame['under_10%'] = dupe_frame['under_10'] / dupe_frame['EntryCount']
|
| 450 |
-
|
| 451 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
background_gradient(cmap='RdYlGn', subset=['uniques%', 'under_5%', 'under_10%'], axis=0).
|
| 453 |
-
background_gradient(cmap='
|
| 454 |
format(dupe_format, precision=2), hide_index=True)
|
|
|
|
| 442 |
st.dataframe(st.session_state['general_frame'].style.background_gradient(cmap='RdYlGn', axis=1).format(precision=2), hide_index=True)
|
| 443 |
|
| 444 |
with tab5:
|
| 445 |
+
with st.form(key='dupe_form'):
|
| 446 |
+
col1, col2 = st.columns(2)
|
| 447 |
+
with col1:
|
| 448 |
+
user_dupe_var = st.selectbox("Which usage(s) would you like to view?", ['All', 'Specific'], key='user_dupe_var')
|
| 449 |
+
with col2:
|
| 450 |
+
user_dupe_select = st.multiselect("Select your user(s)", working_df['BaseName'].sort_values().unique(), key='user_dupe_select')
|
| 451 |
+
submitted = st.form_submit_button("Submit")
|
| 452 |
+
if submitted:
|
| 453 |
+
if user_dupe_var == 'Specific':
|
| 454 |
+
user_dupe_select = user_dupe_select
|
| 455 |
+
else:
|
| 456 |
+
user_dupe_select = None
|
| 457 |
+
|
| 458 |
dupe_frame = working_df[['BaseName', 'EntryCount', 'dupes', 'uniques', 'under_5', 'under_10']]
|
| 459 |
dupe_frame['average_dupes'] = dupe_frame['dupes'].mean()
|
| 460 |
dupe_frame['uniques%'] = dupe_frame['uniques'] / dupe_frame['EntryCount']
|
| 461 |
dupe_frame['under_5%'] = dupe_frame['under_5'] / dupe_frame['EntryCount']
|
| 462 |
dupe_frame['under_10%'] = dupe_frame['under_10'] / dupe_frame['EntryCount']
|
| 463 |
+
dupe_frame = dupe_frame[['BaseName', 'EntryCount', 'average_dupes', 'uniques', 'uniques%', 'under_5', 'under_5%', 'under_10', 'under_10%']].drop_duplicates(subset='BaseName', keep='first')
|
| 464 |
+
st.session_state['duplication_frame'] = dupe_frame.sort_values(by='EntryCount', ascending=False)
|
| 465 |
+
if user_dupe_var == 'Specific':
|
| 466 |
+
st.session_state['duplication_frame'] = st.session_state['duplication_frame'][st.session_state['duplication_frame']['BaseName'].isin(user_dupe_select)]
|
| 467 |
+
|
| 468 |
+
# Initialize pagination in session state if not exists
|
| 469 |
+
if 'dupe_page' not in st.session_state:
|
| 470 |
+
st.session_state.dupe_page = 1
|
| 471 |
+
|
| 472 |
+
# Calculate total pages
|
| 473 |
+
rows_per_page = 50
|
| 474 |
+
total_rows = len(st.session_state['duplication_frame'])
|
| 475 |
+
total_pages = (total_rows + rows_per_page - 1) // rows_per_page
|
| 476 |
+
|
| 477 |
+
# Create pagination controls in a single row
|
| 478 |
+
pagination_cols = st.columns([4, 1, 1, 1, 4])
|
| 479 |
+
with pagination_cols[1]:
|
| 480 |
+
if st.button(f"Previous Page"):
|
| 481 |
+
if st.session_state['dupe_page'] > 1:
|
| 482 |
+
st.session_state.dupe_page -= 1
|
| 483 |
+
|
| 484 |
+
with pagination_cols[3]:
|
| 485 |
+
if st.button(f"Next Page"):
|
| 486 |
+
st.session_state.dupe_page += 1
|
| 487 |
+
|
| 488 |
+
# Calculate start and end indices for current page
|
| 489 |
+
start_dupe_idx = (st.session_state.dupe_page - 1) * rows_per_page
|
| 490 |
+
end_dupe_idx = min((st.session_state.dupe_page) * rows_per_page, total_rows)
|
| 491 |
+
|
| 492 |
+
st.dataframe(st.session_state['duplication_frame'].iloc[start_dupe_idx:end_dupe_idx].style.
|
| 493 |
background_gradient(cmap='RdYlGn', subset=['uniques%', 'under_5%', 'under_10%'], axis=0).
|
| 494 |
+
background_gradient(cmap='RdYlGn', subset=['uniques', 'under_5', 'under_10'], axis=0).
|
| 495 |
format(dupe_format, precision=2), hide_index=True)
|