59 lines
1.1 KiB
Python
59 lines
1.1 KiB
Python
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, hide_UI_elements
|
|
|
|
|
|
print(">>> start of streamlit run")
|
|
|
|
|
|
st.set_page_config(
|
|
page_title="stand",
|
|
page_icon="icon.png",
|
|
layout="wide"
|
|
)
|
|
|
|
hide_UI_elements()
|
|
|
|
|
|
restapi.sid = get_session_id() # rest api needs current session ID to trigger the next rerun
|
|
|
|
changed = restapi.changed
|
|
df = restapi.data
|
|
|
|
|
|
download(df)
|
|
|
|
|
|
# if df in restapi changed, we need to reload it into aggrid.
|
|
# if df in restapi did not change, we do not reload to ensure changes in the browser persist.
|
|
|
|
response = aggrid(
|
|
df,
|
|
reload_data=changed
|
|
)
|
|
|
|
|
|
# if we reloaded, aggrid returns the df from before (why?), thus we do not update the restapi.
|
|
# if we did not reload, aggrid may return an updated df from an edit in the browser,
|
|
# and thus we need to update the restapi.
|
|
|
|
new_df = response["data"]
|
|
if not new_df.equals(df) and not changed:
|
|
restapi.data = df = new_df
|
|
|
|
|
|
if not df.empty:
|
|
print("<<< write hdf")
|
|
df.to_hdf("output.h5", key="data")
|
|
|
|
|
|
print(">>> end of streamlit run")
|
|
|
|
|
|
|