Skip to content

Generate interactive figures in Jupyter Notebooks which can be exported to static HTML webpages

License

Notifications You must be signed in to change notification settings

Robaina/staticInteract

 
 

Repository files navigation

Static Interactive Figures for Jupyter Notebooks

Generate interactive figures in Jupyter which solely depend on JavaScript and can be exported to static HTML webpages. Forked from https://github.com/jakevdp/ipywidgets-static

Install:

pip install staticinteract

I really liked the functionality provided by the, now abandoned, project ipywidgets-static. Contrary to what it is stated in the original repo, iPython's ipywidgets do not provide the same functionality of ipywidgets-static (as far as I know, that is). Specifically, iPython's ipywigets depend on an active Jupyter kernel to work. Thus, interactive figures do not work in situations where there isn't any kernel to support them, such as when displaying the notebook as a webpage after converting it to HTML.

I find it very useful to be able to maintain interactivity of figures in HTML-displayed notebooks. For instance, to share scientific results with colleagues. For this reason I have added some new features to the original project and made it into this package so it's easier to install.

These are the main additions:

  1. First, I updated the code to be compatible with python 3 since I do not use python 2, and it's doomed to disappear anyways.
  2. I added the possibility to store the generated images in a folder instead of embedding them in the notebook. Embedding the images within the notebook makes sense for small interactive plots, i.e., ones which do not generate many images. However, in larger ones the notebook gets soon saturated with embedded images, it's slow to load or simply won't load properly. To solve this issue, images can now be stored outside the notebook, as png files, and are imported to the notebook when called by the interactive plot.
  3. In the previous version, StaticInteract would write the same JavaScript code to the notebook cell where it was called. I find this repetitive and unnecessary, moreover prone to errors due to declaring more than once the same JavaScript variables when multiple interactive plots are done in a single notebook. To solve this issue, this part of JavaScript code is now embedded in the notebook only at the beginning, when the module is imported.

NOTE: The notebook needs to be trusted for interactive figures to work, since untrusted notebooks do not run embedded JavaScript code. Once the Notebook is exported to HTML, interactive figures will continue to work.

About

Generate interactive figures in Jupyter Notebooks which can be exported to static HTML webpages

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 95.2%
  • Python 4.8%