PaleNeutron / streamlit-ext

Streamlit widgets synce value with url ,download button which won't cause rerun and some useful functions
Apache License 2.0
35 stars 2 forks source link

Not sure how to use download_button #1

Closed mabusdogma closed 1 year ago

mabusdogma commented 1 year ago

Hello, I like the idea of not to reload the page everytime you download something, but I just don't know how to use this feature. So far I use this code to dowloand a csv, it works fine (if you ignore it realoads every single time):

    with open("file.csv", "rb") as file:
        st.download_button(
            label='CSV cash alt',
            data=file,
            file_name="file.csv",
            mime="text/csv")

Not sure how to implement this in download for a 'file.csv' that comes from an excel sheet (with variable sheet2)

with this code ste.download_button('CSV cash alt', sheet2, "file.csv") it sends an error page:

RuntimeError: Invalid binary data format: <class 'openpyxl.worksheet.worksheet.Worksheet'>

If I try something like this: ste.download_button('CSV cash alt', "text/csv", "file.csv") Gives me a file with literaly "text/csv" inside!

I hope you can guide me a bit, perhaps I'm not the only one lost in here.

Thank you for this breat idea, and not to reload the page again!

PaleNeutron commented 1 year ago

ste. download_button is implemented exactly the interface of st.download_button now, just replace any st.download_button to ste.download_button, that will make it works.

mabusdogma commented 1 year ago

Oh, my bad!😂 Thanks, now it works!