Ask Your Question
3

Output of @interact disappears when exporting Jupyter notebook to HTML

asked 2019-10-31 03:37:13 +0200

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2019-10-31 21:30:57 +0200

nbruin gravatar image

updated 2019-11-01 17:34:55 +0200

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
edit flag offensive delete link more

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 ( 2019-11-01 01:12:52 +0200 )edit

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 ( 2019-11-01 01:39:58 +0200 )edit

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: 2019-10-31 03:37:13 +0200

Seen: 1,412 times

Last updated: Nov 01 '19