Erva Ulusoy commited on
Commit
0ab12f7
·
1 Parent(s): e6abfd3

added pagination to result page

Browse files
Files changed (1) hide show
  1. ProtHGT_app.py +70 -3
ProtHGT_app.py CHANGED
@@ -104,7 +104,8 @@ with st.sidebar:
104
  )
105
 
106
  if uploaded_file:
107
- protein_list = [line.decode('utf-8').strip() for line in uploaded_file]
 
108
  # Remove empty lines and duplicates
109
  protein_list = list(filter(None, protein_list))
110
  protein_list = list(dict.fromkeys(protein_list))
@@ -305,10 +306,55 @@ if st.session_state.submitted:
305
  filtered_df = filtered_df.sort_values('Probability', ascending=False)
306
 
307
 
308
- # Display the filtered dataframe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  st.dataframe(
310
- filtered_df,
311
  hide_index=True,
 
312
  column_config={
313
  "Probability": st.column_config.ProgressColumn(
314
  "Probability",
@@ -331,6 +377,27 @@ if st.session_state.submitted:
331
  }
332
  )
333
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
  # Download filtered results
335
  st.download_button(
336
  label="Download Filtered Results",
 
104
  )
105
 
106
  if uploaded_file:
107
+ protein_list = [line.strip() for line in uploaded_file.read().decode('utf-8').splitlines()]
108
+
109
  # Remove empty lines and duplicates
110
  protein_list = list(filter(None, protein_list))
111
  protein_list = list(dict.fromkeys(protein_list))
 
306
  filtered_df = filtered_df.sort_values('Probability', ascending=False)
307
 
308
 
309
+ # Custom CSS to increase table width and improve layout
310
+ st.markdown("""
311
+ <style>
312
+ .stDataFrame {
313
+ width: 100%;
314
+ }
315
+ .stDataFrame > div {
316
+ width: 100%;
317
+ }
318
+ .stDataFrame [data-testid="stDataFrameResizable"] {
319
+ width: 100%;
320
+ min-width: 100%;
321
+ }
322
+ .pagination-info {
323
+ font-size: 14px;
324
+ color: #666;
325
+ padding: 10px 0;
326
+ }
327
+ .page-controls {
328
+ display: flex;
329
+ align-items: center;
330
+ justify-content: center;
331
+ gap: 20px;
332
+ padding: 10px 0;
333
+ }
334
+ </style>
335
+ """, unsafe_allow_html=True)
336
+
337
+ # Add pagination controls
338
+ col1, col2, col3 = st.columns([2, 1, 2])
339
+ with col2:
340
+ rows_per_page = st.selectbox("Rows per page", [50, 100, 200, 500], index=1)
341
+
342
+ total_rows = len(filtered_df)
343
+ total_pages = (total_rows + rows_per_page - 1) // rows_per_page
344
+
345
+ # Initialize page number in session state
346
+ if "page_number" not in st.session_state:
347
+ st.session_state.page_number = 0
348
+
349
+ # Calculate start and end indices for current page
350
+ start_idx = st.session_state.page_number * rows_per_page
351
+ end_idx = min(start_idx + rows_per_page, total_rows)
352
+
353
+ # Display the paginated dataframe with increased width
354
  st.dataframe(
355
+ filtered_df.iloc[start_idx:end_idx],
356
  hide_index=True,
357
+ use_container_width=True, # This makes the table use full width
358
  column_config={
359
  "Probability": st.column_config.ProgressColumn(
360
  "Probability",
 
377
  }
378
  )
379
 
380
+ # Pagination controls with better layout
381
+ col1, col2, col3 = st.columns([1, 3, 1])
382
+ with col1:
383
+ if st.button("⬅️ Previous", disabled=st.session_state.page_number == 0):
384
+ st.session_state.page_number -= 1
385
+ st.rerun()
386
+
387
+ with col2:
388
+ st.markdown(f"""
389
+ <div class="pagination-info" style="text-align: center">
390
+ Page {st.session_state.page_number + 1} of {total_pages}<br>
391
+ Showing rows {start_idx + 1} to {end_idx} of {total_rows}
392
+ </div>
393
+ """, unsafe_allow_html=True)
394
+
395
+ with col3:
396
+ if st.button("Next ➡️", disabled=st.session_state.page_number >= total_pages - 1):
397
+ st.session_state.page_number += 1
398
+ st.rerun()
399
+
400
+
401
  # Download filtered results
402
  st.download_button(
403
  label="Download Filtered Results",