Dear Guru,
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.
hi @phong-ssk
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.
Thank you
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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.