Export figurewidgets from jupyter notebook to HTML

#1

Hi folks,

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))
widgets.HBox([fig,fig])

Am I doing something wrong? Any help is welcome

thanks

Alex

#2

Hi @Alexboiboi,

Here’s an approach that works for me.

  1. Run the notebook using the classic JupyterNotebook (not JupyterLab)
  2. Save notebook using the “Widgets -> Save Notebook Widgets State” menu item
  3. 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 iplot approach, the widget JavaScript libraries are pulled form a CDN not embedded in the notebook. So the produced HTML files will require an internet connection.

Hope that helps!
-Jon

#3

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.

#4

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.