-
Notifications
You must be signed in to change notification settings - Fork 79
Jupyter Kernel and Notebook Extensions
Jupyter offers a number of different extension mechanisms. A good overview can be found here.
The datalab
package makes use of a kernel extension for extending the notebook with new line and cell magics,
and a notebook extension which is really just (ab)used as a way to install a number of Javascript files in a location that Jupyter can find them.
The notebook extension needs to be installed once (after installing the datalab package), which is done with:
jupyter nbextension install --py datalab.notebook --sys-prefix
(Note that this requires Jupyter notebook 4.2 or later. The --sys-prefix
causes the extension to be installed in the Python virtualenv; if you are not running in a virtualenv then you should leave that off. But really, you should be in a virtualenv).
That copies the files from datalab/notebook/static
to a place where they can be found provided that they are requested with an nbextensions
prefix in the URL. If you look at the code generated for a chart in Datalab (which you can find in datalab/utils/commands/_utils.py
) you will see something like:
require.config({
...
map: {
'*': {
datalab: 'nbextensions/gcpdatalab'
}
},
This is the magic that allows us to do a require(['datalab/charting'],...)
and have the request remapped to the right place for Jupyter to find the charting.js
file.
The kernel extension can be loaded with %loadext datalab.kernel
within a notebook, or via your config file
as described here. This loads Python code (that can be found in the various datalab.*.commands
modules) to register the cell and line magics used by Datalab. For more information on those see here.