Streamlit rerun

Hi, I would like to rerun my app from a python script, I tried some thing like:
from streamlit.ScriptRunner import RerunException
raise RerunException
I got the following error ModuleNotFoundError: No module named ‘streamlit.ScriptRunner’,
I guess that this module was depreciated. is there any alternative to rerun my app from my script.

1 Like

Hey @khalidbouziane,

There is actually, but it is in our experimental area (see the docs on caveats to using experimental commands).

You can use st.experimental_rerun() at the point where you would like your code to rerun from the top!

Happy Streamlit-ing!
Marisa

3 Likes

thank you for your fast reply, do I need to import a specific model before using st.experimental_rerun(), and which version of streamlit do I need to have

Hey @khalidbouziane,

I’m not sure what you mean by this?

The experimental rerun works with the current version of Streamlit!

I want to say module.

2 Likes

ah!

No, you can use it in any Streamlit script, no additional module imports are needed! :smile_cat:

Happy Streamlit-ing!
Marisa

Hey Hi ! So when I do st.experimental_rerun() , the st.experimental_getqueryparams() are becoming empty meaning the URL is becoming empty is there any way where URL is saved when script is rerun? I need this help because I want to navigate accross pages using URL query params.

Thank you so much i have been searching for this for hours…

1 Like

I am creating a login application where the username and password is being stored in dictionary. because of the app is running for every submit the app is running right from the top I am losing the username data’s that I have stored in dictionary what should I do? does st.experimental_rerun() works here? if yes where should i call this function?

Hi Dharik, welcome to Streamlit! :slight_smile:

For this use case we recently had a session state update which can help save the username when logged in.
To see an example of when I myself had this question you could look through this post:

To learn more about Session state and usage of it you can check this out:

It will probably be something in the form of:

if "username" not in st.session_state:
    st.session_state.username = "the username you want to save"

now you can retrieve it with st.session_state.username :slight_smile:

have a great day!

Thank you Marisa!
These two commands together were very useful in my project:
st.legacy_caching.clear_cache()
st.experimental_rerun()

1 Like