First time here? Check out the FAQ!

Ask Your Question
3

Output of @interact disappears when exporting Jupyter notebook to HTML

asked 5 years ago

Juanjo gravatar image

I would like to write a Jupyter notebook that includes some interacts. When I export it to HTML the output of cells containing an interact disappears completely. The following screen captures shows the problem: the notebook is shown above, the corresponding HTML page appears below.

image description

image description

I was hoping that, at least, an image of the initial state of the interact will be shown. Is there a way to automatically replace the interact output by an image when exporting to HTML?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
4

answered 5 years ago

nbruin gravatar image

updated 5 years ago

This is not really a sage question anymore, since the interact feature is now realized by jupyter widgets, which exists outside of sage as well. That's good, because there is a larger community that may be able to help you.

If you go to "widgets -> embed widgets" you are offered copy-pastable html code that produces exactly the image that you want. So you get html that does what you want.

I haven't been able to find a tool that automatically does the substitutions for you. In fact, this thread (or rather the lack of a satisfying response) suggests this might still be missing functionality.

In general, the ipywidgets documentation is probably the way to go. As mentioned there jupyter-sphinx or nbsphinx may offer the functionality you are looking for.

EDIT: (elevating one of the comments below for better visibility)

The route "File -> Download As -> HTML", after one saves the widgets state, still fails. However, as suggested in the Plotly thread linked above, it can be successfully done through the command line:

$jupyter nbconvert --to html test.ipynb
Preview: (hide)
link

Comments

Many thanks for the hints, in particular, the pointer to the ipywidgets documentation. It is explained there that the notebook can be saved with the widgets state as metadata. The resulting notebook can be correctly rendered through nbviewer, as can be seen here. By now, this solution is enough for me.

Juanjo gravatar imageJuanjo ( 5 years ago )

I have also tested the route "File -> Download As -> HTML" once saved the widgets state. It still fails. However, as suggested in the Plotly thread you linked, it can be successfully done through the command line:

$jupyter nbconvert --to html test.ipynb

Juanjo gravatar imageJuanjo ( 5 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 1,554 times

Last updated: Nov 01 '19