Dataframe not refreshing

Hello Streamlit community,

Currently writing Streamlit app to retrieve options setup on a specific Oracle database hosted on a target platform.
The user selects the folder containing the audit data
Folder name is composed by <server_name>_<Database_name>
Start_analyze button performing logical treatments and display informations for each option in a dataframe from a csv file generated dynamically
So far all Streamlit behavior fine but …Correct options used in the database displayed
Above title is correct (global python variable)

Next attempts (analyzing a different folder name ) retrieve correct data in title but related dataframe is never refreshed and still display data of initial analyze …

Did -with our without setting allow_output_mutation=True

@st.cache (suppress_st_warning=True, allow_output_mutation=True)
def load_data():
    cols = columns=['Server' , 'Instance' ,'Option' , 'Usage_option_count' , 'Thales_subscribed' ,'Date_analysis']
    data_ora = pd.read_csv(config.df_summary, usecols = cols)
    return data_or

I checked config.df_summary value used (target .csv file name) is correct in load_data function, but dataframe never refreshed and still display data with server_name / database_name
values of first analysis … - like on image below example
Also tried of using st.empty() but with no effect

Please advise !

Hi @dominique,

I edited your post to put that code in block quotations so it’s easier to understand, in future posts you should use the same notation to make code more readable!

I don’t know if you copy-pasted your code in or not but there are 2 typos (they might be a problem so I included them, but I think its the real issue reasoning below):

I don’t think you actually want to use @st.cache here for 2 reasons. First, st.cache memorizes the python computations and output of your function. If the function is called with the same parameters it won’t re-execute it will just remember and assign the data from the first time it was executed. This is explained in the examples in the docs.

So because you have called your function load_data() and you don’t pass in any arguments, st.cache sees your function being called again in the exact same way as before and doesn’t run the function at all causing your dataframe to never be updated

Second, it sounds like your data frame is changing quite frequently and st.cache is used to memorize your function output (it doesn’t track if a file has changed at all). And I would argue you actually want the data to be loaded in each time your script runs so that the most up to date data is what you see in your app.


  • there should be no space between st.cache and the brackets to pass in parameters
  • you return data_or and not data_ora in your function

Happy Streamlit-ing!

Hello Marissa,

Thanks for your quick reply on that issue and advices ! :slightly_smiling_face:
There was effectively one typo regarding @st.cache syntax - other was a bad copy/paste :frowning:
Regarding the reasoning by itself, effectively @st.cache should not be used in that case because I rerun the whole script from the beginning - for another stuff to analyze.

But in my previous code I did not told you everything regarding the logic code:
@st.cache has basically its own interest because some logical piece of the code enables to select either with a check box all database options or multi-select list of only some database options to be analyzed and to be displayed graphically - graphic representation of the related dataframe.
Without the whole options choice (not used in my current code attempts) to be displayed ‘@st.cache’ is a non-sense I agree
I’m currently re-writing a Streamlit application by introducing filedialog.askdirectory with tkinter to be able choosing directly target folder…and I found some bug not yet seen before :frowning:

It brings another questions to workaround :

  • Is there a simply way to develop a code functionality (.eg, one button or anther widget) to reset the application by clearing the cache and RE-RUNNING the application logic from the beginning - once the whole logic code completed ?
    This means for an end-user to start another analysis from zero (= in my case, choosing another folder with other audit data analysis to be analyzed) ?
  • Is there an easy way to disable / enable a Streamlit button - to prevent end-user click several times on the same button when it has already be clicked one time ?

I had a look in the forum regarding these 2 questions with no clear answer

Thanks a lot !

Hi @dominique,

No problem!

I’m not sure what you mean by this :slightly_frowning_face: But I think I can help with your questions anyways:

  1. Code to reset: Yes you can as answered in this post with Streamlit v 1.1.0 you can use st.legacy_caching.clear_cache() to reset your caching. If you put this behind a button, every time someone interacts with the code your script reruns from the top, so if you clear the cache and have it rerun I think it should be relatively easy to have your app “reset” to your defaults. (you may need to put the clear cache in a callback function)

  2. disable button: I think with some clever logic you can find a way to remove a button after it has been clicked, or just have the button set behind some logic so that it only appears on your webapp if certain conditions are met. This would likely need to be managed by st.session_state.

Without access to your code I wont be able to help you beyond this!

Good luck! :four_leaf_clover:
Happy Streamlit-ing!

Hello Marisa,

Got a lot of work on the table for the good advises you gave me.
I did not know neither Session state (in its ‘new’ form - but currently use the Session State class picked for older Streamlit versions). or st.legacy_caching.clear_cache …and just discovered the new concept of ‘st.form’ to include widgets into a form in version 1.10 (just upgraded my Streamlit app with this new version)…May help a lot !
So now with these new options I’m ready to perform some improvements to current app’, will be back to you if some clarifications required :wink:
Thanks again !


Iniitial issue solved (global variable not well reset)
Related dataframe correctly refreshed
Thanks again for your support :grinning: