switched to object syntax for columns; use to_hdf_binary; some cleanup

This commit is contained in:
2022-05-23 12:54:33 +02:00
parent 48c163f9d7
commit 159bfca9b1

View File

@ -1,32 +1,31 @@
import streamlit as st import streamlit as st
from utils.df_utils import to_excel_binary from utils.df_utils import to_excel_binary, to_hdf_binary
state = st.session_state
def download(df): def download(df):
showing_downloads = st.session_state.get("showing_downloads", False) showing_downloads = state.get("showing_downloads", False)
col1, col2, col3, col4 = st.columns([1, 1, 1, 1]) col0, col1, col2, col3 = st.columns(4)
with col1: if col0.button("Downloads") and not showing_downloads:
if st.button("Downloads") and not showing_downloads: state.showing_downloads = True
st.session_state.showing_downloads = True
with col2: h5 = to_hdf_binary(df)
with open("output.h5", "rb") as f: col1.download_button("📥 hdf5", h5, file_name="output.h5")
st.download_button("📥 hdf5", f, file_name="output.h5")
with col3: xlsx = to_excel_binary(df)
xlsx = to_excel_binary(df) col2.download_button("📥 xlsx", xlsx, file_name="output.xlsx")
st.download_button("📥 xlsx", xlsx, file_name="output.xlsx")
with col4: csv = df.to_csv()
csv = df.to_csv() col3.download_button("📥 csv", csv, file_name="output.csv")
st.download_button("📥 csv", csv, file_name="output.csv")
# st.stop() # st.stop()
else: else:
st.session_state.showing_downloads = False state.showing_downloads = False