Streamlit and plotly

Hi, I am having trouble saving a plotly generated charts.

According to documentation to save it as png I’m using fig.write_image(“images/fig1.png”). This doesn’t seem to work however. Did anyone else experience this issue before? Exporting to html works fine. Saving plots from matplotlib works too.

Hello @wron, welcome to the community !

When you say fig.write_image, are you talking about using kaleido ? Do you have an error message showing ?
If you can provide a little code snippet, it would be super helpful :slight_smile:

Best,
Fanilo

Yes, I’m trying to use kaleido.
I installed it using pip install -U kaleido
Here’s an example of what I’m trying to do

count = df.value_counts()
fig = go.Figure(data=[go.Pie(labels=count.index.tolist(),
                            values=count.values)])

fig.write_image("fig1.png")
st.plotly_chart(fig)

Chart works fine when I’m not trying to save it.
Thanks :slightly_smiling_face:

1 Like

Fixed it with this

1 Like

Great ! Thanks for sharing back the answer too, much appreciated :blush:

Fanilo