Diego Marroquin commited on
Commit ·
f0ee368
1
Parent(s): 6e2dd81
Debugging
Browse files
app.py
CHANGED
|
@@ -562,7 +562,7 @@ def run_app():
|
|
| 562 |
|
| 563 |
st.title("Data Filters")
|
| 564 |
df_columns_lst = df.columns.tolist()
|
| 565 |
-
print(df_columns_lst)
|
| 566 |
|
| 567 |
# Select columns for display
|
| 568 |
selected_columns = st.sidebar.multiselect("Select Columns to Display",
|
|
@@ -589,6 +589,10 @@ def run_app():
|
|
| 589 |
print("st.write(filtered_df)")
|
| 590 |
|
| 591 |
# Add a download button
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
current_datetime = datetime.datetime.now()
|
| 593 |
current_year = current_datetime.strftime('%Y')
|
| 594 |
current_month = current_datetime.strftime('%m')
|
|
@@ -597,22 +601,42 @@ def run_app():
|
|
| 597 |
current_minute = current_datetime.strftime('%M')
|
| 598 |
current_second = current_datetime.strftime('%S')
|
| 599 |
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 605 |
|
| 606 |
-
|
| 607 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 608 |
|
| 609 |
-
# Provide the BytesIO object to the download button
|
| 610 |
-
download_button = st.download_button(
|
| 611 |
-
label="Download Excel",
|
| 612 |
-
data=excel_buffer,
|
| 613 |
-
file_name=f"nucmonitor_data_{current_year}-{current_month}-{current_day}-h{current_hour}m{current_minute}s{current_second}.xlsx",
|
| 614 |
-
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 615 |
-
)
|
| 616 |
|
| 617 |
if __name__ == '__main__':
|
| 618 |
run_app()
|
|
|
|
| 562 |
|
| 563 |
st.title("Data Filters")
|
| 564 |
df_columns_lst = df.columns.tolist()
|
| 565 |
+
print("df_columns_lst", df_columns_lst)
|
| 566 |
|
| 567 |
# Select columns for display
|
| 568 |
selected_columns = st.sidebar.multiselect("Select Columns to Display",
|
|
|
|
| 589 |
print("st.write(filtered_df)")
|
| 590 |
|
| 591 |
# Add a download button
|
| 592 |
+
# Create a BytesIO object to hold the Excel data
|
| 593 |
+
excel_buffer = io.BytesIO()
|
| 594 |
+
|
| 595 |
+
|
| 596 |
current_datetime = datetime.datetime.now()
|
| 597 |
current_year = current_datetime.strftime('%Y')
|
| 598 |
current_month = current_datetime.strftime('%m')
|
|
|
|
| 601 |
current_minute = current_datetime.strftime('%M')
|
| 602 |
current_second = current_datetime.strftime('%S')
|
| 603 |
|
| 604 |
+
with st.form("unfiltered_excel_form"):
|
| 605 |
+
unfiltered_submitted = st.form_submit_button("Get Unfiltered Excel")
|
| 606 |
+
|
| 607 |
+
with st.form("filtered_excel_form"):
|
| 608 |
+
filtered_submitted = st.form_submit_button("Get Filtered Excel")
|
| 609 |
+
|
| 610 |
+
if unfiltered_submitted:
|
| 611 |
+
# Save the DataFrame to the BytesIO object as an Excel file
|
| 612 |
+
df.to_excel(excel_buffer, index=True)
|
| 613 |
+
# Set the cursor position to the beginning of the BytesIO object
|
| 614 |
+
excel_buffer.seek(0)
|
| 615 |
+
|
| 616 |
+
# Provide the BytesIO object to the download button
|
| 617 |
+
download_button = st.download_button(
|
| 618 |
+
label="Download Excel",
|
| 619 |
+
data=excel_buffer,
|
| 620 |
+
file_name=f"nucmonitor_data_{current_year}-{current_month}-{current_day}-h{current_hour}m{current_minute}s{current_second}.xlsx",
|
| 621 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 622 |
+
)
|
| 623 |
|
| 624 |
+
elif filtered_submitted:
|
| 625 |
+
# Save the DataFrame to the BytesIO object as an Excel file
|
| 626 |
+
filtered_by_plant.to_excel(excel_buffer, index=True)
|
| 627 |
+
# Set the cursor position to the beginning of the BytesIO object
|
| 628 |
+
excel_buffer.seek(0)
|
| 629 |
+
|
| 630 |
+
# Provide the BytesIO object to the download button
|
| 631 |
+
download_button = st.download_button(
|
| 632 |
+
label="Download Excel",
|
| 633 |
+
data=excel_buffer,
|
| 634 |
+
file_name=f"nucmonitor_data_{current_year}-{current_month}-{current_day}-h{current_hour}m{current_minute}s{current_second}.xlsx",
|
| 635 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 636 |
+
)
|
| 637 |
+
else:
|
| 638 |
+
pass
|
| 639 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 640 |
|
| 641 |
if __name__ == '__main__':
|
| 642 |
run_app()
|