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