D3 4.0+ does not create d3 global variable when importing into Jupyter Notebook

The following errors will not be executed using the JavaScript ReferenceError :

 from IPython.display import HTML, display display(HTML(""" <script src="https://d3js.org/d3.v4.js"></script> <script> console.log(d3); </script> """)) 

Why?

The equivalent version of D3 3.x will work (although in the second attempt, for me):

 from IPython.display import HTML, display display(HTML(""" <script src="https://d3js.org/d3.v3.js"></script> <script> console.log(d3); </script> """)) 

This is the most relevant question / answer I could find on this topic.

+4
source share
2 answers

This turned out to be due to an internal change in the d3 export method. Version 3.x d3 branch exported all its internal components as global variables ( source code ); Version 4.x no longer does this ( source code ). Instead, a package manager (such as require.js ) is expected, and the export will be sent to it instead.

For more information, see the GitHub props .

Now you should do something like:

 <script src="scripts/require.js"></script> <script>var d3 = require('d3')</script> 

After that, everything should work as expected.

+1
source

I have the solution described here:

http://makeyourowntextminingtoolkit.blogspot.co.uk/2016/09/interactive-d3v4js-in-jupyter-notebook.html

Essentially, you need to use require.js .., which is already available through the laptop’s own infrastructure.

+1
source

Source: https://habr.com/ru/post/1270920/


All Articles