Download button appearing twice after clicking on it

download button appearing twice after clicking on it…

I have a pandas dataframe which is generated by my code… I’m trying to convert it into excel file and then allow user to download the excel file… but when i’m clicking on the button, exact same button is appearing right below that button and download is starting only when i’m clicking on that second download button.

Steps to reproduce

        # Save output file to BytesIO object
        output_buffer = BytesIO()
        with pd.ExcelWriter(output_buffer) as writer:
            output_df.to_excel(writer, index=False)

        # Add download button
        if st.button("Download Output"):
            output_buffer.seek(0)
            st.download_button(
                label="Download Output",
                data=output_buffer,
                file_name="output.xlsx",
                mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )

Expected behavior:

If I click on the download button, it should start the download immediately

Actual behavior:

two download button are appearing when i click on the download button. and download starts after clicking on the second download button.

Debug info

  • Streamlit version: latest
  • Python version: latest

You have two buttons in your code, first a regular button st.button("Download Output") and then a download button st.download_button(label="Download Output", ...).

If you don’t want two buttons, then get rid of the first one so you only have the one download button. You don’t need to nest the real download button inside a regular button.

1 Like

Thank you very much…