I have a function that pulls data from my supabase database.
@st.cache_data
def pull_selected_files(tables, columns):
data = {}
dtypes = {}
for table in tables:
col_selection = columns.get(table, '*')
if isinstance(col_selection, list):
col_selection = ','.join(col_selection)
st.write(f"Pulling data for table: {table}, columns: {col_selection}")
query = st.session_state["client"].table(table).select(col_selection)
response = execute_query(query)
if response and response.data:
df = pd.DataFrame(response.data)
data[table] = df
dtypes[table] = df.dtypes.to_dict()
data[table]['source'] = 'database'
return data, dtypes
I then need to access the data on different pages, but I am struggling to find it. Do I get the data by calling the function again? or do is it stored in a session state?
here is what I have tried:
if "data" not in st.session_state:
st.warning("No data loaded. Please load data from the database first.")
else:
data = st.session_state["data"]
dtypes = st.session_state["dtypes"]
and
st.write(data)