2

I'm newer in "ipython notebook" and I would to create a custom widget with ipywidgets using html and javascript. I'm using a javascript library and I wanna know if there is a way to import it inside ipython notebook.

thank u in advance

3 Answers 3

5

I found the solution you just need the put the file somewhere in your machine and then use the magic cell HTML like this:

%%HTML
<script src="path-to-your-file"></script>
Sign up to request clarification or add additional context in comments.

Comments

4

The way to import javascript files for use in a custom widget is to use require.config to load the script into the widget. For example, if you wanted to load fabric.js from https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.7.0/fabric.min.js, you would do the following (note that you don't include the ".js" in the path!)

%%javascript
require.undef('hello');
require.config({
  //Define 3rd party plugins dependencies
  paths: {
    fabric: "https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.7.0/fabric.min"
  }
});
define('hello', ["@jupyter-widgets/base", 'fabric'], function(widgets) {...

Comments

2

You might want to look into custom.js file it can be found in the Users\username\.ipython\profile_default\static\custom (or jupyter depending on installed versions). Here you can add links to your js files and they will run each time you open the notebooks.

Also you can have a look into notebook extensions (like these for example )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.