ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 01 Nov 2019 01:39:58 +0100Output of @interact disappears when exporting Jupyter notebook to HTMLhttps://ask.sagemath.org/question/48563/output-of-interact-disappears-when-exporting-jupyter-notebook-to-html/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](/upfiles/1572489201647630.png)
![image description](/upfiles/15724893284633615.png)
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?Thu, 31 Oct 2019 03:37:13 +0100https://ask.sagemath.org/question/48563/output-of-interact-disappears-when-exporting-jupyter-notebook-to-html/Answer by nbruin for <p>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.</p>
<p><img alt="image description" src="/upfiles/1572489201647630.png"></p>
<p><img alt="image description" src="/upfiles/15724893284633615.png"></p>
<p>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?</p>
https://ask.sagemath.org/question/48563/output-of-interact-disappears-when-exporting-jupyter-notebook-to-html/?answer=48574#post-id-48574This 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](https://community.plot.ly/t/export-figurewidgets-from-jupyter-notebook-to-html/15556) (or rather the lack of a satisfying response) suggests this might still be missing functionality.
In general, [the ipywidgets documentation](https://ipywidgets.readthedocs.io/en/latest/embedding.html) is probably the way to go. As mentioned there [jupyter-sphinx](https://jupyter-sphinx.readthedocs.io/en/latest/) or [nbsphinx](https://nbsphinx.readthedocs.io/en/0.4.3/index.html) 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.ipynbThu, 31 Oct 2019 21:30:57 +0100https://ask.sagemath.org/question/48563/output-of-interact-disappears-when-exporting-jupyter-notebook-to-html/?answer=48574#post-id-48574Comment by Juanjo for <p>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.</p>
<p>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.</p>
<p>I haven't been able to find a tool that automatically does the substitutions for you. In fact, <a href="https://community.plot.ly/t/export-figurewidgets-from-jupyter-notebook-to-html/15556">this thread</a> (or rather the lack of a satisfying response) suggests this might still be missing functionality.</p>
<p>In general, <a href="https://ipywidgets.readthedocs.io/en/latest/embedding.html">the ipywidgets documentation</a> is probably the way to go. As mentioned there <a href="https://jupyter-sphinx.readthedocs.io/en/latest/">jupyter-sphinx</a> or <a href="https://nbsphinx.readthedocs.io/en/0.4.3/index.html">nbsphinx</a> may offer the functionality you are looking for.</p>
<p><strong>EDIT:</strong> (elevating one of the comments below for better visibility) </p>
<blockquote>
<p>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:</p>
<pre><code>$jupyter nbconvert --to html test.ipynb
</code></pre>
</blockquote>
https://ask.sagemath.org/question/48563/output-of-interact-disappears-when-exporting-jupyter-notebook-to-html/?comment=48576#post-id-48576Many 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](https://nbviewer.jupyter.org/), as can be seen [here](https://nbviewer.jupyter.org/urls/dl.dropbox.com/s/5debljib7xrp27a/test.ipynb). By now, this solution is enough for me.Fri, 01 Nov 2019 01:12:52 +0100https://ask.sagemath.org/question/48563/output-of-interact-disappears-when-exporting-jupyter-notebook-to-html/?comment=48576#post-id-48576Comment by Juanjo for <p>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.</p>
<p>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.</p>
<p>I haven't been able to find a tool that automatically does the substitutions for you. In fact, <a href="https://community.plot.ly/t/export-figurewidgets-from-jupyter-notebook-to-html/15556">this thread</a> (or rather the lack of a satisfying response) suggests this might still be missing functionality.</p>
<p>In general, <a href="https://ipywidgets.readthedocs.io/en/latest/embedding.html">the ipywidgets documentation</a> is probably the way to go. As mentioned there <a href="https://jupyter-sphinx.readthedocs.io/en/latest/">jupyter-sphinx</a> or <a href="https://nbsphinx.readthedocs.io/en/0.4.3/index.html">nbsphinx</a> may offer the functionality you are looking for.</p>
<p><strong>EDIT:</strong> (elevating one of the comments below for better visibility) </p>
<blockquote>
<p>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:</p>
<pre><code>$jupyter nbconvert --to html test.ipynb
</code></pre>
</blockquote>
https://ask.sagemath.org/question/48563/output-of-interact-disappears-when-exporting-jupyter-notebook-to-html/?comment=48577#post-id-48577I 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
```Fri, 01 Nov 2019 01:39:58 +0100https://ask.sagemath.org/question/48563/output-of-interact-disappears-when-exporting-jupyter-notebook-to-html/?comment=48577#post-id-48577