diff --git a/download.py b/download.py new file mode 100644 index 0000000..34b7dcc --- /dev/null +++ b/download.py @@ -0,0 +1,32 @@ +import streamlit as st + +from utils.df_utils import to_excel_binary + + +def download(df): + showing_downloads = st.session_state.get("showing_downloads", False) + + col1, col2, col3, col4 = st.columns([1, 1, 1, 1]) + with col1: + if st.button("Downloads") and not showing_downloads: + st.session_state.showing_downloads = True + + with col2: + with open("output.h5", "rb") as f: + st.download_button("📥 hdf5", f, file_name="output.h5") + + with col3: + xlsx = to_excel_binary(df) + st.download_button("📥 xlsx", xlsx, file_name="output.xlsx") + + with col4: + csv = df.to_csv() + st.download_button("📥 csv", csv, file_name="output.csv") + + # st.stop() + + else: + st.session_state.showing_downloads = False + + + diff --git a/stand.py b/stand.py index cf61083..b4ea169 100644 --- a/stand.py +++ b/stand.py @@ -3,9 +3,10 @@ import streamlit as st import hacks from aggrid import aggrid +from download import download from restapi import restapi from utils.st_utils import get_session_id, rerun, hide_UI_elements -from utils.df_utils import to_excel_binary + st.set_page_config( @@ -28,31 +29,7 @@ df = restapi.data print(">>> start of streamlit run") - -showing_downloads = st.session_state.get("showing_downloads", False) - -col1, col2, col3, col4 = st.columns([1, 1, 1, 1]) -with col1: - if st.button("Downloads") and not showing_downloads: - st.session_state.showing_downloads = True - - with col2: - with open("output.h5", "rb") as f: - st.download_button("📥 hdf5", f, file_name="output.h5") - - with col3: - xlsx = to_excel_binary(df) - st.download_button("📥 xlsx", xlsx, file_name="output.xlsx") - - with col4: - csv = df.to_csv() - st.download_button("📥 csv", csv, file_name="output.csv") - -# st.stop() - - else: - st.session_state.showing_downloads = False - +download(df) response = aggrid(