Rerun function not working after deployment

When running locally, I had no issues. However, once deployed, the app started to not behave the way I anticipated.

I deployed it in local internal server.

Python version: 3.11.5
Streamlit version: 1.31.0

For some info, when my app begins, it uses the date the app got initiated to make an updated query. Using this query, I successfully retrieve information from a DB.

In addition, I also added a “reload” button to reinitiate the process in case the data is not up-to-date. (I build this in case the deployed app did not have updated data)

However, ever since I deployed the app, the data has not been updated. Furthermore, the reload/rerun functionality doesn’t seem to work. However, every other widgets work fine.

I’m guessing this issue is due to

  • caching
  • streamlit losing its capability to rerun the script once deployed
    • not sure if this is true but I’m assuming it

I would appreciate any help!!

Can you share a minimal, executable code snippet or link to your repository?

st.rerun works fine both locally and remotely, but it’s difficult to provide guidance without understanding how you are reading, writing, and caching your data.

So your saying for example if i had a button in streamlit, that when clicked the st.rerun() function is ran, the code will reload even if the app is deployed, i previously though that st.rerun() doesn’t work on deployed apps

Hi @JibreelOG. All Streamlit functions should work the same both for local and deployed apps. That holds true for st.rerun. The thing that might trip people up is environment configuration and access to local files.

Local files

When you deploy an app to a cloud service, the Python code is running on some remote machine. Any file paths it works with will be on the remote machine. For Community Cloud (for example), if you don’t include a file in your repository or you use global paths in your app, then your deployed app won’t work as it did locally.

Environment configuration

If you don’t install all the necessary Python packages (or any additional software) on the remote machine running your, then it won’t function.

You can read more about the client-server structure of Streamlit, but I can’t think of any function that wouldn’t work the same for local and deployed apps.

1 Like

thankyou for the detailed response,
is it possible to deploy my streamlit app on my own server? For example a reaspberry pi so all my local files are still accesible for the program

or could i put my text file on a google drive and have the information pulled from their

Yes, you can deploy your app elsewhere. There are a few threads on the forum about making Raspberry Pi work. IIRC, I managed to get a Streamlit app running on a Raspberry Pi once, but there were a few particulars like using a Linux OS and I think miniconda… (it’s been a while).

Aside from deploying elsewhere where you have more control over the files, a general solution is to either include your data file in your repo so it’s copied along with your app code, or host your data file somewhere. If you have some sort of spreadsheet or CSV file you need, you could indeed use Google Sheets for that.

1 Like

Amazing thankyou so much i didnt expect the forrums to be this helpful

    if st.button(
        label = "Find related Sub-Topics/Events",
        key="sub_topics",
        on_click=set_state,
        args=[1, True],
        disabled=st.session_state.busy
    ):
        st.session_state.query = metadata.query
        st.session_state.language = metadata.language
        st.session_state.articles_response = {}

        presets = metadata.model_dump()

        with st.spinner("Looking for Trending Topics..."):
            st.session_state.response = invoke_api(topics_api_url, presets)

        st.session_state.busy = False
        st.rerun()

I have this code block which runs perfectly fine locally. But, when deployed it keeps rerunning code block in spinner and is stuck making API calls.

After defining the undefined names your code works as expected for me, both locally and deployed to streamlit cloud. No unexpected reruns.

I don’t know what’s happening in your invoke_api method. It could be relying on a local cookie for authentication, and that’s why it’s working locally and not when deployed. You’ll need to investigate the dependencies within invoke_api to make sure a deployed app has access to everything it needs.

One additional note: Apps on Community Cloud can get hit with rate limits since public APIs can’t distinguish one app from another. If you’re using a public API and others on Community Cloud are using that same public API, it might not work because of rate limiting.

The

invoke_api

is just a get request to an internal public api that has no auth and very low traffic. The issue was the the rerun was not working as expected and it keeps looping. Even after getting the output in that block of button

The code you posted is fine and works in streamlit cloud. The problem must be somewhere else, maybe another part of your code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.