Streamlit app does not update with new data

Hi,
I have a streamlit app deployed in github here:

The underlying data, ie files/latest_measurements.csv does get updated every half hour as imposed by the workflow action, however the streamlit app does not, unless I go and clear the cache as developer. The data in the app that fail to be updated is under the 'Latest measurements" header with latest meteo measurements with a UTC timestamp.

Here is the screenshot from the app, showing that the latest data is from Aug 18, 17:00 UTC

Here is the current data in github that shows that the latest data is from 19 Aug, 07:30 UTC (will probably be something even more recent if you check it yourself as the data is updated once every half hour.

What I did?

  • Earlier in the development phase, when I committed and pushed to streamlit_app.py, things were getting updated such as texts without me including the streamlit_app.py in the workflow action named .github/workflows/get_latest_measurements.yml (actually dont know why and how but anyway, it seemed to work). So I added a `run python streamlit_app.py’ step to the workflow to make sure the code is run.
  • The second thing: I realised that when I clear the cache manually data do get updated. So I added st.cache_resource.clear() at the start of the streamlit_app.py hoping this would solve the issue.

OK I think I found the error. Before I define my function to read data I had @st.cache_data like:

@st.cache_data
def get_df(filename):
    print('Reading df')
    DATA_FILENAME = Path(__file__).parent/filename
    tmp_df = pd.read_csv(DATA_FILENAME)
    print ('df read with shape ',tmp_df.shape,' and type ',type(tmp_df))
    return tmp_df

Removing @st.cache_data and inserting st.cache_data.clear() instead solve the issue. Maybe st.cache_data.clear() is not even necessary now, but I have not tried it yet.

And in the first message, I wrote that I added run streamlit_app.py to the workflow, which proved to be unnecessary. Without this, the app does update!

1 Like

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