Aakarsh
Aakarsh

Reputation: 51

How can I load external static Javascript files in ipython or jupyter notebook

I am trying to load d3 and dimple.js in ipython notebook but its throwing error. I have tried require as well but not able to load please provide me some way out of it

Upvotes: 2

Views: 3475

Answers (1)

Kumar Vairakkannu
Kumar Vairakkannu

Reputation: 179

  1. Run this in the notebook to find out your jupyter directory:

    from jupyter_core.paths import jupyter_config_dir
    jupyter_dir = jupyter_config_dir()
    jupyter_dir
    
  2. Create folder named 'custom' under jupyter directory found from above /custom

  3. Create custom.js file under /custom/custom.js and add following

    requirejs.config({
    paths: {
        d3: 'd3.min',
    }
    });
    
  4. Open jupyter_notebook_config.py created for your profile. if it is not created ,use the following to create one from the command line/terminal

    jupyter notebook --generate-config
    
  5. Modify static path for your js folder in jupyter_notebook_config.py(created from generate-config command) like below

    c.NotebookApp.extra_static_paths = ["C:\your-js-folder"]
    
  6. Drop your external js file under C:\your-js-folder and stop and start jupyter notebook

Upvotes: 6

Related Questions