{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# AngularJS feat. requireJS (as dependency to Jupyter Notebook)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# standard IPython modules for working with frontend output\n", "from IPython.display import SVG, Javascript, HTML, display\n", "\n", "# Gotta pimp the package that makes things easier\n", "import simplejson as json" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A basic partial template file with AngularJS directives" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cat: templates/input_template.ng: No such file or directory\n" ] } ], "source": [ "# We can just read the file with Jupyter's shell commands \"!\"\n", "!cat templates/input_template.ng" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## We can load the dependencies files by reading into IPython.display.javascript" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cat: js/deps.js: No such file or directory\n" ] } ], "source": [ "# Dependency js, although it can't be loaded via Javascript() the file for display\n", "!cat js/deps.js" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prepare a python dictionary with some values\n", "`kernel.execute(\"print(python_dict)\")` will be executed by javascript" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/plain": [ "'{\"input\": \"templates/input_template.ng\", \"input_id\": \"content\"}'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "python_dict = {\"input\": \"templates/input_template.ng\", \"input_id\": \"content\"}\n", "json.dumps(python_dict)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "data": { "text/html": [ "
Note the html ID=\"container\"
\n",
"Note the html ID=\"container\"
\n",
"