Streamlit Download Graph Updated May 2026

💡 Always use io.BytesIO() when handling downloads in Streamlit. It keeps your app fast by processing everything in RAM instead of cluttering your server with temporary files. To help you get this working perfectly, let me know:

import streamlit as st import plotly.express as px # 1. Create a graph fig = px.scatter(df, x="x_column", y="y_column", title="Interactive Export") # 2. Display the graph st.plotly_chart(fig) # 3. Create the download button html_bytes = fig.to_html().encode() st.download_button( label="Download Graph as HTML", data=html_bytes, file_name="interactive_chart.html", mime="text/html" ) Use code with caution.

If you need a high-quality PNG or PDF for a presentation, you can use Plotly's write_image function. streamlit download graph

Hover your mouse over the top-right corner of any Plotly chart.

If you want your users to keep the interactivity (zooming and hovering) offline, the best method is saving the chart as a standalone HTML file. 💡 Always use io

This requires the kaleido library installed ( pip install kaleido ).

This is a manual user action and doesn't allow you to trigger a download via a custom Streamlit button. 2. Downloading Plotly Charts as HTML Create a graph fig = px

If you use , Altair , or Vega-Lite , Streamlit displays these charts using a frontend component that already includes a download button.