How to add a download excel/csv function to a button?

Thanks for the useful replies and cross post linking everyone!

I got my Excel file download working with a combination of openpyxl, using wb.save("test.xlsx") to save it to the current app dir and then jamming that file into:
file = f'<a href="test.xlsx" download="test.xlsx">Download excel file</a>'
and using st.markdown(file, unsafe_allow_html=True) to actually show a download link.

I use a regular st.button to generate the new Excel file and then the markdown link to download gets generated underneath it.

I wish Streamlit would add a great looking download button like the one that you posted feliperoque :slight_smile:
It’s a bit weird that we’ve had the file_uploader widget for quite some time but no nice button to download files(and no way to link a regular st.button to download a file).

Might have to find some time to learn how those UI components are built in Streamlit so I can try to build one.

1 Like