Skip to content
Weston Hunter edited this page Mar 5, 2015 · 79 revisions

The IPython notebook functionality (i.e. what you do with the Browser) can be extended using Javascript extensions. This repository contains a collection of such extensions. The maturity of the provided extensions may vary, please create an issue if you encounter any problems.

IPython version support

IPython Version Description
1.x not supported
2.x checkout 2.x branch
3.x checkout 3.x branch

For version 3.x information click here: 3.x (current IPython master branch)

There are different branches of the notebook extensions in this repository. Please make sure you use the branch corresponding to your IPython version. Not all extensions may be available in 2.x and 3.x.

Note: This is not related to the Python version.

#Overview for IPython Version 2.x The repository is organized in different categories:

Name Description
usability Additional functionality for the notebook
publishing Getting your notebooks out in the wild
styling Styling schemes for different looks of the notebook
slidemode Slideshow creation
testing Extensions in a early stage

##Usability

File or Directory Description
aspell Spellchecker using aspell
breakpoints Allow setting of breakpoints to stop execution of notebook cells
codefolding Fold code blocks using Alt-F or clicking on gutter
comment-uncomment.js Toggle comments in selected lines using Alt-C
executeTime.js Display when each cell has been executed and how long it took
help_panel.js Display panel with hotkey help
hide_input_all Hide all codecells in a notebook
linenumbers.js Add line numbers to code cells
navigation-hotkeys.js Change hotkeys for navigation in notebook
python-markdown.js Display Python variables in markdown
read-only.js Allow codecells to be set read-only, so no editing is possible
rubberband Multi-cell selection tool
runtools Add toolbar buttons for additional code execution options
search.js Search notebook for expressions
shift-tab.js Assign "shift-tab" key to dedent tabulator

##Publishing

File or Directory Description
printview-button Add a toolbar button to call nbconvert --to html for current the notebook and display html in new browser tab. Uses current user profile.
printviewmenu-button Add a toolbar button to call menu entry File->Print Preview directly (V2 only)
gist_it Publish notebook as a gist
nbviewer_theme
htmltools/js_highlight.py A python tool to customize the css classes of nbconvert's html code blocks to fit your favourite JS syntax highlighter

##Styling

File or Directory Description
styling/css_selector
styling/zenmode

##Slidemode

File or Directory Description
slidemode Make slide creation for reveal.js easier

##Testing

File or Directory Description
hierarchical_collapse Adds a button to hide all cells below the selected heading
history
swc
cellstate

General installation instruction

Notebook extensions can be installed by copying the corresponding javascript extension and it's accompanying files to the nbextensions directory of your local IPython directory (aka IPYTHONDIR) and calling it either directly in a notebook or adding it to the custom.js in your local profile.

Installing from a URL

The easiest way to install an extension is directly from IPython:

import IPython
IPython.html.nbextensions.install_nbextension('https://rawgithub.com/minrk/ipython_extensions/master/nbextensions/gist.js')

You can verify if your extension has been installed by using

IPython.html.nbextensions.check_nbextension('gist.js')

Manual installation

First you need to find your local IPython directory. This can be done from command line:

ipython locate

or in IPython by executing:

import IPython
ip=IPython.get_ipython()
ip.ipython_dir

Now copy your notebook extension files in the nbextensions subdirectoy.

Interactive loading of a notebook extension

Once the notebook extension has been installed, they can be loaded like this:

%%javascript
IPython.load_extensions('gist');

Automatic loading of a notebook extension

If you want an extension to be always loaded, you need to call it in your local custom.js file. First locate your profile directory:

import IPython
ip=IPython.get_ipython()
ip.config.ProfileDir 

This will give you something like {'location': u'C:\\Users\\me\\.ipython\\profile_dev'} or for Unix {'location': u'/home/you/.ipython/profile_default'}

So your file will be located here: /home/you/.ipython/profile_default/static/custom/custom.js

This is where you add a line to call your notebook extension. How to do this is described in the next section.

Adding the extension to custom.js

Your custom.js should look like this:

// activate extensions only after Notebook is initialized
require(["base/js/events"], function (events) {
$([IPython.events]).on("app_initialized.NotebookApp", function () {
    /* load your extension here */
    IPython.load_extensions('gist');
    });
});

In the example above, the gist.js is loaded. Note: You don't need to specify the .js file extension.

A template custom.js file is given here : ipython-contrib/custom.example.js

It is also possible to add additional locations where extensions or the custom.js file can be placed. This can be configured in the ipython_notebook_config.py file. To find out if you have configured an extra path type:

ip.config.NotebookApp.extra_static_paths

Troubleshooting

If the extension does not work, here is how you can check what is wrong:

  1. Clear your browser cache or start a private browser tab.
  2. Verify your custom.js is the one the IPython notebook is seeing, by opening it in the browser: http://127.0.0.1:8888/static/custom/custom.js
    (as opposed to ../site-packages/IPython/html/static/custom/custom.js,
    which may the only custom.js loaded if you are using a virtualenv)
  3. Verify the extension can be loaded by the IPython notebook, for example: http://127.0.0.1:8888/nbextensions/gist.js
  4. Check for error messages in the JavaScript console.

Clone this wiki locally