Saving the Plotly Chart as .png or .jpeg file format locally

Hello @amrit !

Could you share the snippet for using pdfkit to produce an html that reads images from a folder you’re trying to use? There might be 2 things to worry about:

  1. For static image export of plotly I usually go with Kaleido to write in tempfile locally so hopefully that should work for you too
import plotly.express as px
fig = px.scatter(px.data.iris(), x="sepal_length", y="sepal_width", color="species")
fig.write_image(<some_tempfile>, engine="kaleido")
  1. Depending on your code, the way you link to an image in your html template before reading with pdfkit could not work because the work folder is not accessible by the HTML file. This may be a thing to solve by for example saving the temp image in the Streamlit static folder (not sure we need to go as far as this, should depend on your code :wink: )

Have a nice day,
Fanilo :balloon:

2 Likes