2

I'm having troubles installing extensions in IPython. The problem is that i can't get the extensions load automatically, i have followed the instructions in the github page but it just doesn't work. According the the homepage i need to modify the custom.js file by adding some lines. I want to install the codefolding, hide_input_all and runtools extensions. This is how my custom.js file looks:

// 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('usability/codefolding/codefolding')
 IPython.load_extensions('usability/runtools/runtools')
 require(['/static/custom/hide_input_all.js'])
 });
});

The extensions work well if i call them manually, for example, if i type

%%javascript
IPython.load_extensions('usability/runtools/runtools/main');

the runtools appear and works perfectly, but i want the extensions to be loaded automatically and not to have to call them manually every time. Could someone tell me where is my mistake?

Isak Baizley
  • 1,722
  • 4
  • 16
  • 21
  • Your manual code has an extra `/main` that's not there in your custom.js - could that be relevant? – Thomas K Mar 24 '15 at 21:04
  • This question is similar to: http://stackoverflow.com/questions/32046241/how-to-add-automatically-extension-to-jupiter-ipython-notebook – Vasco Nov 18 '15 at 08:22

1 Answers1

3

There's been a little change to the syntax. Nowadays, $ might not be defined by the time your custom.js loads, so instead of something like

$([IPython.events]).on("app_initialized.NotebookApp", function () {
    IPython.load_extensions("whatever");
});

you should do something like

require(['base/js/namespace', 'base/js/events'], function(IPython, events) {
    events.on('app_initialized.NotebookApp', function(){
        IPython.load_extensions("whatever");
    })
});

with the appropriate changes to braces and parentheses. For me, the former will work more often than not, but certainly not always; it fails maybe ~1/3 of the time.

If that doesn't do it for you, open up Developer Tools (or whatever is relevant for your browser) and look at the javascript console for errors. That'll help figure out what's going wrong.

Mike
  • 19,114
  • 12
  • 59
  • 91