How to call load_data using a button?

Hi all,

My streamlit application is fueled by database data, which gets updated several times every day. I would like the users to be able to refresh the application data upon request. This process is a bit heavy, so I am really happy about the cache functionality. However, the users should be able to ask for an update of the data. Is that possible, e.g. using a button?

Hi @quba9210, welcome to the Streamlit community!

The cache is based on the function inputs; if nothing gets mutated, then the cache doesn’t recalculate. So conceptually, you could add another argument to your data loading function called counter or something similar, then have your button increment the counter:

#pseudocode

counter = 0

@st.cache()
def dataload(file, counter)
 #do something
 return data

if button:
  counter += 1

Something like that would change the cache arguments each time someone presses the button, and that should re-load the file for you.

Let me know if this helps, or if you’re still stuck I’ll post a working code snippet.

Best,
Randy

Thanks a lot. Will try this.