66 lines
1.3 KiB
Python
66 lines
1.3 KiB
Python
from pathlib import Path
|
|
|
|
import streamlit as st
|
|
|
|
import hacks
|
|
|
|
from widgets.aggrid import aggrid
|
|
from widgets.download import download
|
|
from restapi import restapi
|
|
from utils.st_utils import get_session_id, hide_UI_elements
|
|
|
|
|
|
print(">>> start of streamlit run")
|
|
|
|
icon = Path(__file__).parent.parent / "icon.png"
|
|
|
|
st.set_page_config(
|
|
page_title="stand",
|
|
page_icon=str(icon),
|
|
layout="wide",
|
|
initial_sidebar_state="collapsed"
|
|
)
|
|
|
|
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)
|
|
|
|
|
|
height = st.sidebar.slider(
|
|
"Grid Height",
|
|
min_value=100, max_value=1500, value=500, step=10,
|
|
key="grid_height"
|
|
)
|
|
|
|
|
|
# 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,
|
|
height=height
|
|
)
|
|
|
|
|
|
# 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 = new_df
|
|
|
|
|
|
print(">>> end of streamlit run")
|
|
|
|
|
|
|