I’m currently using
docxtpl to generate a series of Word files within Streamlit. After the files are generated, I want to have a download button that allows me to download all the newly created files with just one click.
Many thanks in advance!
Why you are not creating a single zip or archive file in which includes all your files and then downloading them?
Here are some tips from my side:
To enable users to download multiple Word files generated within a Streamlit app with a single click, you can employ the
st.download_button component in combination with a zip archive.
Generate Word Files: Ensure that you’ve created your Word files using the
docxtpl library and saved them locally in a directory.
Create a Zip Archive: Before adding the download button, generate a zip archive containing the Word files. Python’s
zipfile module is useful for this task. Iterate through your Word files directory, adding each file to the zip archive.
Integrate the Download Button: In your Streamlit app, introduce the download button. When clicked, it triggers the download of the zip archive. Ensure that the
zip_filename variable points to the location of your zip archive.
Hope it will help you @phong-ssk, if you have any further doubts do ask.
Dear @abdulrehman ,
I am a beginner in Python and Streamlit. I am currently working on a project in Streamlit Cloud. I would appreciate your advice. I will try to follow your instructions. I am still working on the code, and I will reply soon if it works for me.
Thank you for your time and consideration.