-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Problem
The download button currently expects its data to be available when declaring the button. If data needs to be read from disk (or worse: compiled multiple disk sources), this can make the app needlessly slow.
In my app, the data downloading is not a common use case, but the packing of the data for downloading is relatively expensive. Caching helps, but only when the data doesn't change.
Solution
I propose a method to only load and preprocess (archive, pickle, etc) when the download is actually requested.
I propose to also allow a function as a data type that gets called as soon as the download button is pressed. This callback then returns the actual data.
def get_data():
data = some_heavy_data_loading()
return data
st.download_button("Download Data", get_data, file_name="my-data.dat")Possible additions:
Currently a download button accepts str, bytes, TextIO, BinaryIO, or io.RawIOBase. With deferred loading, it would also be possible to accept a file pointer and stream the data to the user. This might bring huge speed and memory benefits when downloading large files.
Technically this streaming would also be possible without deferred loading, but then you're keeping unnecessary files open.
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.