From 21a06c97821080d6a04e476e62ac8c3697b35d7e Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sun, 22 May 2022 21:50:38 +0200 Subject: [PATCH] refactor --- stand.py | 7 ++----- utils/__init__.py | 4 ++++ utils/utils.py | 9 +++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 utils/utils.py diff --git a/stand.py b/stand.py index 3ad18c7..d0115c4 100644 --- a/stand.py +++ b/stand.py @@ -4,6 +4,7 @@ from st_aggrid import AgGrid, GridOptionsBuilder import hacks from restapi import restapi +from utils import make_key from utils.st_utils import get_session_id, rerun, hide_UI_elements from utils.df_utils import to_excel_binary @@ -24,10 +25,6 @@ changed = restapi.changed df = restapi.data -# encode the column names into the key, thus trigger a hard reload (like F5) when the columns change -key = "stand:" + "+".join(str(col) for col in df.columns) - - print(">>> start of streamlit run") @@ -77,7 +74,7 @@ response = AgGrid( fit_columns_on_grid_load=True, reload_data=changed, - key=key + key=make_key(df) ) diff --git a/utils/__init__.py b/utils/__init__.py index e69de29..30ce09d 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -0,0 +1,4 @@ + +from .utils import * + + diff --git a/utils/utils.py b/utils/utils.py new file mode 100644 index 0000000..5317770 --- /dev/null +++ b/utils/utils.py @@ -0,0 +1,9 @@ + +def make_key(df): + """ + encode the column names into the key, + this triggers a hard reload (like F5) when the columns change + """ + return "stand:" + "+".join(str(col) for col in df.columns) + +