├── LICENSE ├── README.md ├── index.ipynb ├── postBuild └── requirements.txt /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019, Binder Project 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Enabling Jupyter Extensions with post-build commands 2 | 3 | [![Binder](https://mybinder.org/badge_logo.svg)](https://beta.mybinder.org/v2/gh/binder-examples/jupyter-extension/HEAD?urlpath=/tree/index.ipynb) (Jupyter Notebook) 4 | 5 | [![Binder](https://mybinder.org/badge_logo.svg)](https://beta.mybinder.org/v2/gh/binder-examples/jupyter-extension/HEAD?urlpath=lab/tree/index.ipynb) (Jupyter Lab) 6 | 7 | 8 | This example demonstrates how to enable Jupyter extensions with Binder.We currently only cover one example 9 | in this repo. Be aware that some are idiosyncratic in how they're enabled. 10 | 11 | We accomplish each step using a `requirements.txt` file to install the extension, 12 | then a `postBuild` file to enable it. 13 | 14 | ## ipywidgets 15 | 16 | Ipywidgets lets you create interactive widgets in your notebook. 17 | Installation is fairly straightforward. You install the python package, 18 | then enable the extension. 19 | 20 | The postBuild file defines commands (one per line) to be run with bash. 21 | In this case, we first enable the ipywidgets extension in the classic notebook interface. We then use it to install a Jupyter Lab extension 22 | (by calling jupyter labextension) which allows ipywidgets 23 | to be displayed within notebooks. 24 | -------------------------------------------------------------------------------- /index.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import matplotlib.pyplot as plt\n", 10 | "import numpy as np\n", 11 | "from ipywidgets import interact\n", 12 | "from ipywidgets.widgets import IntSlider, Dropdown\n", 13 | "plt.ion()" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# Ipywidgets" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 2, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "data = np.logspace(0, 2, 100)\n", 30 | "data = np.tile(data, [100, 1])\n", 31 | "data += np.random.randn(100, 100) * 50\n", 32 | "data += np.linspace(0, 1000, 100)[:, np.newaxis]" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "data": { 42 | "application/vnd.jupyter.widget-view+json": { 43 | "model_id": "14bcec67909a43598eaca5a05a8f5e30", 44 | "version_major": 2, 45 | "version_minor": 0 46 | }, 47 | "text/plain": [ 48 | "interactive(children=(IntSlider(value=0, description='ii', max=99), Dropdown(description='cmap', options=('coo…" 49 | ] 50 | }, 51 | "metadata": {}, 52 | "output_type": "display_data" 53 | } 54 | ], 55 | "source": [ 56 | "cmaps = ['coolwarm', 'viridis', 'magma']\n", 57 | "def plot_data(ii, cmap):\n", 58 | " fig, ax = plt.subplots()\n", 59 | " cmap = plt.get_cmap(cmap)\n", 60 | " color = cmap(ii / 100.)\n", 61 | " ax.plot(data[ii], color=color)\n", 62 | " ax.set_ylim([0, 1000])\n", 63 | " plt.show()\n", 64 | " \n", 65 | "p = interact(plot_data, ii=IntSlider(0, 0, 99), cmap=Dropdown(options=cmaps))" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [] 74 | } 75 | ], 76 | "metadata": { 77 | "kernelspec": { 78 | "display_name": "Python 3", 79 | "language": "python", 80 | "name": "python3" 81 | }, 82 | "language_info": { 83 | "codemirror_mode": { 84 | "name": "ipython", 85 | "version": 3 86 | }, 87 | "file_extension": ".py", 88 | "mimetype": "text/x-python", 89 | "name": "python", 90 | "nbconvert_exporter": "python", 91 | "pygments_lexer": "ipython3", 92 | "version": "3.7.3" 93 | } 94 | }, 95 | "nbformat": 4, 96 | "nbformat_minor": 2 97 | } 98 | -------------------------------------------------------------------------------- /postBuild: -------------------------------------------------------------------------------- 1 | jupyter contrib nbextension install --user 2 | jupyter nbextension enable --py widgetsnbextension 3 | jupyter labextension install @jupyter-widgets/jupyterlab-manager@0.38 --minimize=False 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | ipywidgets 4 | jupyter_contrib_nbextensions --------------------------------------------------------------------------------