{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Appmode in Jupyter\n", "\n", "This page demonstrates how to generate online \"apps\" with a Jupyter Notebook interface. With the `appmode` plugin, we can create interactive experiences without requiring coding or running a specific cell.\n", "\n", "Markdown cells will be retained, and all code cells will be run, then hidden. The outputs of each cell will be displayed as well.\n", "\n", "Check out a further example using an [ipyvolume](https://ipyvolume.readthedocs.io/en/latest/) to render a 3D plot: [ipyvolume_demo.ipynb](ipyvolume_demo.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import division\n", "import ipywidgets as ipw\n", "\n", "output = ipw.Text(placeholder=\"0\", layout=ipw.Layout(width=\"190px\"), disabled=True)\n", "\n", "def on_click(btn):\n", " if btn.description == \"=\":\n", " try:\n", " output.value = str(eval(output.value))\n", " except:\n", " output.value = \"ERROR\"\n", " elif btn.description == \"AC\":\n", " output.value = \"\"\n", " elif btn.description == \"del\":\n", " output.value = output.value[:-1]\n", " else:\n", " output.value = output.value + btn.description\n", "\n", "def mk_btn(description):\n", " btn = ipw.Button(description=description, layout=ipw.Layout(width=\"45px\"))\n", " btn.on_click(on_click)\n", " return btn\n", "\n", "row0 = ipw.HBox([mk_btn(d) for d in (\"(\", \")\", \"del\", \"AC\")])\n", "row1 = ipw.HBox([mk_btn(d) for d in (\"7\", \"8\", \"9\", \" / \")])\n", "row2 = ipw.HBox([mk_btn(d) for d in (\"4\", \"5\", \"6\", \" * \")])\n", "row3 = ipw.HBox([mk_btn(d) for d in (\"1\", \"2\", \"3\", \" - \")])\n", "row4 = ipw.HBox([mk_btn(d) for d in (\"0\", \".\", \"=\", \" + \")])\n", "ipw.VBox((output, row0, row1, row2, row3, row4))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }