whitphx / streamlit-server-state

A "server-wide" state object shared across sessions on a Streamlit server.
https://discuss.streamlit.io/t/new-library-streamlit-server-state-a-new-way-to-share-states-over-the-sessions-on-the-server/14981
MIT License
138 stars 13 forks source link

Multi page application #167

Open bandoos opened 1 year ago

bandoos commented 1 year ago

Hello @whitphx, thanks a lot for this library, great work!

I have a question regarding its usage in multipage streamlit applications.

It seems there is a bit of glitches when the application has multiple pages. To reporduce what I'm talking about just create a main_page.py besides the app_chat.py containing just

import streamlit as st
st.header("Main page")

create a pages directory besides main_page.py and copy app_chat.py to it. Now streamlit run main_page.py should open a multipage app, navigate to the chat page with the sidebar, open 2 instances in 2 browser tabs and try to chat. It looks like on some (but not all) occasions the reload also forces the other app go back to main page instead of chat page.

Let me know if you can reproduce the bug!

piyopiyo13 commented 1 year ago

I'm having a similar issue. I have an app with an st.selectbox providing access to the different pages. I also have a background Thread from threading periodically updating a pandas DataFrame stored in server_state. I've noticed that whenever this DataFrame gets refreshed, the ensuing rerun causes the browser to return to the main page. The dropdown menu corresponding to the st.selectbox maintains the user-selected value in the browser, but if I call st.write on st.session_state, it shows that the variable value of the st.selectbox has been overwritten with the main page. It almost seems like the rerun is a "hard" rerun, where st.session_state is getting reset to default values.

I've tried suppressing the rerun by wrapping updates with no_rerun, planning on using the package st_autorefresh to do the reruns from the client side instead, but get the below error. I probably need to clarify ctx for the thread, but I'm not sure exactly what to do.

/miniconda3/lib/python3.9/site-packages/streamlit_server_state/rerun_suppression.py", line 23, in __enter__
    setattr(ctx, _SERVER_STATE_RERUN_SUPPRESSION_ATTR_NAME_, True)
AttributeError: 'NoneType' object has no attribute '__SERVER_STATE_SUPPRESS_RERUN__'
kk19990709 commented 1 year ago

I'm facing the same question, wondering how to fix