When creating an html from a plotly plot using the to_hmtl method, the generated html can be displayed correctly using display(HTML(x)) when using JupyterLab but is not displayed correctly when using Jupyter Notebook (nothing is displayed).
Also, when trying to export the Jupyter Lab notebook to hmtl using nbconvert, the plotly plot are not correctly shown in the generated html (although they are rendered correctly in the JupyterLab Notebook)
Python Code
import plotly.graph_objs as go
from IPython.display import HTML, display
# Create some sample data
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
# Create a trace
trace = go.Scatter(
x=x,
y=y,
mode='markers',
marker=dict(
size=10,
color='blue'
)
)
# Create a data list with the trace
data = [trace]
# Create a layout
layout = go.Layout(
title='Example Scatter Plot',
xaxis=dict(title='X-axis'),
yaxis=dict(title='Y-axis')
)
# Create a figure with the data and layout
fig = go.Figure(data=data, layout=layout)
html_fig = fig.to_html()
display(HTML(html_fig))
Yes you right. the html version of the plot isnβt displayed. Iβm wondering why anyone would want to convert to html a Plotly figure generated in the Jupyter Notebook, and then display it again in Jupyter notebook, while fig.show() could do this job. I have been using Plotly for 10 years and have never, absolutely never needed to perform such a βtrickβ.
Thank you for confirming the problem. I am generating a standard html report using a jinja2 template and I am embedding the plotly plots as html in the report. Then I sometime need to render this report (or several) inside a Jupyter Notebook to document my work. I guess it is kind of a non standard solution but in my case fig.show() will not do the trick.
Any ideas how to solve the issue?
I am also encountering the problem of the plotly html not showing in a jupyter notebook, despite the cell running successfully. I use notebooks to collate a wide variety of other plots and data. Would greatly appreciate if anyone can offer a solution.
Why use an html? I want to retain the interactivity of the plotly plot, but not have to regenerate the plot each time. This is due to speed and also convenience, as I am often displaying plots from a variety of locations.