'require' callback not getting called from jupyter notebook

Viewed 231

I am trying to use D3 in a jupyter notebook (w/ python 2.x kernel). Several website explain how to do this but it looks like my require callback function is not getting called.

Here is some (simplified) code:

from IPython.display import SVG, Javascript, HTML

The following correctly shows "hi" in the result area

%%javascript
element.append("hi");

Copy paste from some website:

%%javascript
require.config({
  paths: {
      d3: '//d3js.org/d3.v4.min.js'
  }
});

Executing above results in no errors

%%javascript
require(['domReady', 'd3'], function(domReady, d3){
    domReady(function(){
        console.log("test4");
    });
    console.log("test2");
    element.append("hi")
});
console.log("test3");

The snipped above only prints 'test3' to the console. This tells me that the callback function is never being called! (the domReady business is in there because someone on the web suggested that it might resolve some loading race condition issues).

As you can see, the problem seems to be with the require call, it is not even getting to d3!

This notebook is running Python kernel 2.7. Jupyter version itself is currently JupyterLab v0.27.0, but I installed this just a few moments earlier. Prior to this, I was using whatever is the standard Jupyter version available from 'conda install ...'

0 Answers
Related