Option for lazy evaluation st.download_button

The download button needs to be passed the data upon rendering the button, so if you want to delay the gathering/compiling of that data then you may be forced into using a custom component or script injection.

Here is a post about scripting a download from just before the download button existed so you can modify it to your needs:

Here’s the associated gist: autodownload-csv.py · GitHub

And here’s a GitHub feature request you can vote on to get the requested functionality added to the download button in Streamlit: Defered data for download button · Issue #5053 · streamlit/streamlit · GitHub