parente.dev

Code Hiding on nbviewer

April 08, 2016

When this notebook first loads on nbviewer, all of the input cells are hidden. To reveal them, click the element tag icon in the top right of nbviewer. Click it again to hide them once more.

The last code cell loads a CDN-hosted script to enable the show/hide interactivity. The script encapsulates the recipe from http://chris-said.io/2016/02/13/how-to-make-polished-jupyter-presentations-with-optional-code-visibility/.

It's cool, too, that the plot.ly example remains interactive on nbviewer as well.

In [1]:
%matplotlib inline
In [2]:
from plotly.offline import init_notebook_mode, iplot, iplot_mpl
import matplotlib.pyplot as plt
import numpy as np
In [3]:
init_notebook_mode()
In [4]:
n = 50
x, y, z, s, ew = np.random.rand(5, n)
c, ec = np.random.rand(2, n, 4)
area_scale, width_scale = 500, 5
In [5]:
fig, ax = plt.subplots()
sc = ax.scatter(x, y, c=c,
                s=np.square(s)*area_scale,
                edgecolor=ec,
                linewidth=ew*width_scale)
ax.grid()

iplot_mpl(fig)

In [6]:
%%html
<script src="https://cdn.rawgit.com/parente/4c3e6936d0d7a46fd071/raw/65b816fb9bdd3c28b4ddf3af602bfd6015486383/code_toggle.js"></script>

Another Read: Four Ways to Extend Jupyter Notebook »

Jupyter Notebook (née IPython Notebook) is a web-based environment for interactive computing in notebook documents. In addition to supporting the execution of user-defined code, Jupyter Notebook has a variety of plug-in points that you can use to extend the capabilities of the authoring environment itself. In this post, I'll touch on four of these extension mechanisms and finish off with a word on packaging and distribution: