Stop users from switching pages while performing an action on the existing page


Hi Everyone, I have a function which takes a couple of seconds to run in a multi page app, and the result is stored in the session state for usage on the other pages where necessary.

How do I ensure that while this function is running, the user cannot switch pages and disrupt the function?

Another solution would be to allow the user to switch pages while the function is still running in the background, and eventually the variable is still saved to the session state.

Hi @nathanham16

A possible approach is to use st.selectbox (st.selectbox - Streamlit Docs) as a Navigation drop-down to navigate to various pages. Next, you can disable the selectbox when a computation process is under way via the disabled parameter by setting it to True.

Hope this helps!

1 Like