Last week, I filled an hour in a department seminar showing ways in which we could use to Jupyter notebooks to support the creation and use of interactive educational materials.
I’ve no idea if it converted anyone to the cause.
I could have done any number of other talks — about the architecture of the Jupyter ecosysytem more widely (at least, insofar as I understand), or the way in which Jupyter makes sense for reproducible research and how it fits into a containerised / virtualised way of working.
Because Jupyter is not just about notebooks.
It’s also about string and glue.
Here’s something I suddenly grokked the other day whilst chatting to somebody about different ways of accessing applications that have a graphical UI… (on a desktop, on a desktop in a VM, via X11
(“what’s that?” they asked… sigh…), via a browser if is has an HTML UI, via novnc
in a browser window if it doesn’t (albeit w/ borked audio support); note to self – try out this novnc
Jupyter extension.): if you wrap an application that has a command line interface using metakernel, you can access it in a notebook, or JupyterLab.
Obvious, right? But that means I can also access it via a web page using something like ThebeLab (or Juniper, or nbinteract), run via a container launched using Binderhub.
This is all tied up with a couple of the Big Ideas that underlies Jupyter: firstly, that it supports the read/write web. Secondly that it supports remote code execution (and as such enables the read/write/execute web).
So for example, one of the many metakernel based kernels is the gnuplot_kernel
that lets you run Gnuplot commands from a notebook code cell and display the generated figure in a notebook. Here’s a forked version with the repo tweaked so it runs on MyBinder.
Using a gnuplot_kernel
enabled Binder repo, we can now run Gnuplot commands via a web-browser using the ThebeLab Javascript package, for example, and display the result in the same web page. The container on the back is fired up in response to the first command issued from the page, which make take up to a minute or two, and will be used for future commands issued from the page in the same session.
Here’s what it looks like:
(The Gnuplot code is ripped from an example in the Gnuplot docs / gallery.)
The code seems to be repeated in the output, but I guess a tweak to the ThebeLab settings, or code, may fix that. Or maybe the kernel needs a tweak. But the proof of concept is there…
Here’s the code for the web page (image file, sorry… WordPress-com editor’n’sourcecode support sucks and I get fed up faffing around with tag brackets each time I re-edit the page):
That source code image does make a second point, though… Look closely, and compare the URLs in the two images above: I can edit an HTML file via the Jupyter notebook text file editor, and also render the page as a served HTML file.
So that’s a couple more things for my colleagues to say “ah, but it won’t work for my course because…”
Bring it on…
PS the code as a gist:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> | |
<title>Thebe Lab examples</title> | |
<link rel="stylesheet" type="text/css" href="index.css" /> | |
<!– Configure and load Thebe !–> | |
<script type="text/x-thebe-config"> | |
{ | |
bootstrap: true, | |
binderOptions: { | |
repo: "ouseful-PR/gnuplot_kernel", | |
}, | |
kernelOptions: { | |
name: "gnuplot", | |
}, | |
} | |
</script> | |
<script type="text/javascript" src="https://unpkg.com/thebelab@^0.3.0"></script> | |
<!– or to use a local build: –> | |
<!– <script type="text/javascript" src="../lib/index.js"></script> –> | |
</head> | |
<body> | |
<h1>Thebe Lab – Gnuplot demo</h1> | |
<p>Press <tt>Shift-Enter</tt> to execute the following cell. Launching the | |
computation backend may take a few seconds, and you may need to | |
re-execute it.</p> | |
If we wrap an application using metakernel, we can access it via a browser… | |
<pre data-executable="true" data-language="gnuplot">plot sin(x)</pre> | |
</body> | |
</html> |
PPS Interested in keeping up to date with Jupyter news? Sign up to the Tracking Jupyter weekly newsletter.
I think I see what you talking about via twitter now. To get your MyBinder launch to work, I had to enter “! python -m gnuplot_kernel install –user” (to install the kernelspec) in a Python notebook, Then it could open the gnuplot kernel… but then it never loaded completely. But mybinder can do the kernelspec install, right?
Hmm… the kernel install is in the postBuild in my repo? Gnuplot should also be installed? Demo notebooks work for me? https://mybinder.org/v2/gh/ouseful-PR/gnuplot_kernel/master?filepath=examples%2Fgnuplot-kernel.ipynb