How to download file in streamlit

As you may see in the download_button function, there is an if alse statement if picle_it, inside else statement there is another if else statement in which it checks the distance.

        elif isinstance(object_to_download, pd.DataFrame):
            object_to_download = object_to_download.to_csv(index=False)

you can see that there is written that if instance is pd.DataFrame, then you should use method ‘to_csv’
you need to change it to: pd.dataframe.to_excel() for more info check it here:pandas.DataFrame.to_excel — pandas 1.2.4 documentation

I hope it will work for you :slight_smile:

1 Like

I did those changes you said but didn’t worked. Instead, returned the following error:

elif isinstance(object_to_download, pd.DataFrame):
     object_to_download = object_to_download.to_excel(index=False)

i also changed the donwload_button extesion:

tmp_download_link = download_button(cg_result_dataframe, f'cg_result_dataframe.xlsx', button_text='Donwload Cg Dataframe 💾')

Try to do this:

hope it will help :slight_smile:

How can I download Image . I didn’t get that.
please anyone can provide code for that. @czubert

I just now saw this thread. Maybe this post from me could be of help?

Did @jgieseler solution work for you? :speak_no_evil:

@Bhavya_Soni try this

I also face this problem, and need a good solution.
I tried the solution of like this:

with open(zip_path, “rb”) as f:
bytes =
    b64 = base64.b64encode(bytes).decode()
    href = f'<a href="data:file/zip;base64,{b64}" download=\'{filename}.zip\'>\
        Click to download\
st.sidebar.markdown(href, unsafe_allow_html=True)

this solution will report RuntimeError:Data of size 280MB exceeds write limit of 50MB.

related topic link:

How to download file in streamlit - Using Streamlit - Streamlit

Hey all :wave:,

We now have Download Button natively supported in Streamlit via the 0.88.0 release with st.download_button!

To use, upgrade to the latest version:
pip install --upgrade streamlit

Helpful links:

Looking forward to hearing what you think :balloon:

1 Like

Hey streamlit team,

Great feature! Looks much more clean and allowed me to even remove some lines of code!

Thanks a lot!

1 Like