I would need to share the content of some jupyter notebooks in a HTML format. Normal figures displayed by the iplot command work fine, but the Figurewidgets are not supported in the export and do not show up.
As an example, the following code works well in jupyterlab but i cannot export it to html (using the export menu):
import pandas as pd
import plotly.graph_objs as go
import ipywidgets as widgets
x = np.linspace(0,2*np.pi,10)
y = np.sin(x)
trace = go.Scatter(x=x,y=y)
data = [trace]
fig = go.FigureWidget(dict(data=data))
Am I doing something wrong? Any help is welcome
Here’s an approach that works for me.
- Run the notebook using the classic JupyterNotebook (not JupyterLab)
- Save notebook using the “Widgets -> Save Notebook Widgets State” menu item
- Use nbconvert on the command line to convert the notebook to HTML (See https://github.com/jupyter/nbconvert). I have
nbconvert version 5.4.0 installed.
$ jupyter nbconvert --to html mynotebook.ipynb
As far as I know, it’s not yet possible to save the notebook widget state to the notebook using JupyterLab. And the notebooks own “File -> Download As -> HTML” doesn’t embed the widget info inte exported HTML.
Also note that unlike the
Hope that helps!
thanks for your help, I will try this. Let’s hope Jupyterlab will be able to save the notebook widget state in some near future update.
I don’t know if this worked for @Alexboiboi , but I’ve tried this example and the solution provided by @jmmease and still getting nothing when I open the saved HTML. Any other suggested approaches or advice is welcome.
Same as @Yannly, tried this exact same solution, and the exported HTML notebook had no figures showing.
@jmmease can you please advise if you found an alternative solution?
Steps 1. and 2. can now be done within the recent JupyterLab versions by enabling the setting “Settings” -> “Save Widget State Automatically” and saving the notebook.
You still have to run
nbconvert from the command line as in Step 3, since “Export Notebook to HTML” still doesn’t work with Plotly.