{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Notes taken from the online [tutorial](https://jakevdp.github.io/blog/2013/06/01/ipython-notebook-javascript-python-communication/) about embedding javascript in ipython notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Learning Notes\n", "### Executing python from within javascript\n", "\n", "The key functionality needed for interaction between javascript and the `IPython kernel` is the kernel object in the IPython Javascript package. Use `IPython.display.HTML` for embedded html and javascript display \n", "\n", "```javascript\n", "var kernel = IPython.notebook.kernel;\n", "kernel.execute(command);\n", "```\n", "\n", "or with a callback function in javascript\n", "\n", "```javascript\n", "var kernel = IPython.notebook.kernel;\n", "function callback(out_type, out_data){\n", " // do_something\n", "}\n", "kernel.execute(command, {\"output\": callback});\n", "```" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "