plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.07k stars 2.54k forks source link

plotly.io.write_html return #3599

Open radcoreai opened 2 years ago

radcoreai commented 2 years ago

Hello!

I am trying to convert a plotly plot to an HTML embeddable div (reproducible example below):

import plotly.express as px
import plotly

fig = px.scatter([1,2], [3,4])
html = plotly.io.write_html(fig, "fig.html")

type(html)
NoneType

While the string representation of the HTML is indeed written to the file, the documentation clearly says that the method returns the string representation.

Returns Representation of figure as an HTML div string

As for my use case it would be great to have the string directly returned so I can use it externally (to avoid an useless write-read operation each time I want to generate a HTML plot). Either that or let's update the docs to remove the confusion?

I could solve it either way; Let me know what you think would be the best solution.

Thank you!

nicolaskruchten commented 2 years ago

Yeah, looks like the docstring there is incorrect. write_html() writes to a file and to_html() returns the string :)