|
6 | 6 | "source": [ |
7 | 7 | "# Introduction\n", |
8 | 8 | "\n", |
9 | | - "The notebook comes alive with the interactive widgets" |
| 9 | + "The Juptyer architecture allows you to send messages for code execution to a kernel not only by typing code, but also by using interactive graphical controls such as sliders, menus, check-boxes and more. These can be used with minimal effort to provide easy interactive exploration of parameters in many common cases. With some additional work, sophisticated, multi-control interfaces can be built." |
10 | 10 | ] |
11 | 11 | }, |
12 | 12 | { |
13 | 13 | "cell_type": "markdown", |
14 | 14 | "metadata": {}, |
15 | 15 | "source": [ |
16 | | - "## Speeding up the bottleneck in the REPL\n", |
17 | | - "\n", |
18 | | - "<img src=\"images/Flow.svg\"></img>" |
| 16 | + "Let's first define a simple function that prints the square of its inputs:" |
19 | 17 | ] |
20 | 18 | }, |
21 | 19 | { |
22 | 20 | "cell_type": "code", |
23 | 21 | "execution_count": 1, |
24 | 22 | "metadata": {}, |
25 | | - "outputs": [ |
26 | | - { |
27 | | - "data": { |
28 | | - "text/plain": [ |
29 | | - "81" |
30 | | - ] |
31 | | - }, |
32 | | - "execution_count": 1, |
33 | | - "metadata": {}, |
34 | | - "output_type": "execute_result" |
35 | | - } |
36 | | - ], |
37 | | - "source": [ |
38 | | - "9*9" |
39 | | - ] |
40 | | - }, |
41 | | - { |
42 | | - "cell_type": "code", |
43 | | - "execution_count": 2, |
44 | | - "metadata": {}, |
45 | 23 | "outputs": [], |
46 | 24 | "source": [ |
47 | 25 | "def f(x):\n", |
|
50 | 28 | }, |
51 | 29 | { |
52 | 30 | "cell_type": "code", |
53 | | - "execution_count": 3, |
| 31 | + "execution_count": 2, |
54 | 32 | "metadata": {}, |
55 | 33 | "outputs": [ |
56 | 34 | { |
|
65 | 43 | "f(9)" |
66 | 44 | ] |
67 | 45 | }, |
| 46 | + { |
| 47 | + "cell_type": "markdown", |
| 48 | + "metadata": {}, |
| 49 | + "source": [ |
| 50 | + "We can explore the behavior of $f(x)$ for $x$ in $[0,100)$ using `interact` from `ipywidgets`:" |
| 51 | + ] |
| 52 | + }, |
68 | 53 | { |
69 | 54 | "cell_type": "code", |
70 | | - "execution_count": 4, |
| 55 | + "execution_count": 3, |
71 | 56 | "metadata": {}, |
72 | 57 | "outputs": [], |
73 | 58 | "source": [ |
74 | | - "from ipywidgets import *" |
| 59 | + "from ipywidgets import interact, FloatSlider, FloatText, link, VBox" |
75 | 60 | ] |
76 | 61 | }, |
77 | 62 | { |
78 | 63 | "cell_type": "code", |
79 | | - "execution_count": 6, |
| 64 | + "execution_count": 4, |
80 | 65 | "metadata": {}, |
81 | 66 | "outputs": [ |
82 | 67 | { |
83 | | - "name": "stdout", |
84 | | - "output_type": "stream", |
85 | | - "text": [ |
86 | | - "2500\n" |
87 | | - ] |
| 68 | + "data": { |
| 69 | + "application/vnd.jupyter.widget-view+json": { |
| 70 | + "model_id": "737cd63370ec4812a382d029ab884f58", |
| 71 | + "version_major": 2, |
| 72 | + "version_minor": 0 |
| 73 | + }, |
| 74 | + "text/plain": [ |
| 75 | + "interactive(children=(IntSlider(value=50, description='x'), Output()), _dom_classes=('widget-interact',))" |
| 76 | + ] |
| 77 | + }, |
| 78 | + "metadata": {}, |
| 79 | + "output_type": "display_data" |
88 | 80 | } |
89 | 81 | ], |
90 | 82 | "source": [ |
|
102 | 94 | }, |
103 | 95 | { |
104 | 96 | "cell_type": "code", |
105 | | - "execution_count": 8, |
| 97 | + "execution_count": 5, |
106 | 98 | "metadata": {}, |
107 | 99 | "outputs": [ |
108 | 100 | { |
109 | 101 | "data": { |
110 | 102 | "application/vnd.jupyter.widget-view+json": { |
111 | | - "model_id": "a42ce83f9eb64c89bd792578c8373a34", |
| 103 | + "model_id": "f8d528c364214f41a9786578c4826d41", |
112 | 104 | "version_major": 2, |
113 | 105 | "version_minor": 0 |
114 | 106 | }, |
|
134 | 126 | }, |
135 | 127 | { |
136 | 128 | "cell_type": "code", |
137 | | - "execution_count": 9, |
| 129 | + "execution_count": 6, |
138 | 130 | "metadata": {}, |
139 | 131 | "outputs": [ |
140 | 132 | { |
141 | 133 | "data": { |
142 | 134 | "application/vnd.jupyter.widget-view+json": { |
143 | | - "model_id": "a42ce83f9eb64c89bd792578c8373a34", |
| 135 | + "model_id": "f8d528c364214f41a9786578c4826d41", |
144 | 136 | "version_major": 2, |
145 | 137 | "version_minor": 0 |
146 | 138 | }, |
|
165 | 157 | }, |
166 | 158 | { |
167 | 159 | "cell_type": "code", |
168 | | - "execution_count": 10, |
| 160 | + "execution_count": 7, |
169 | 161 | "metadata": {}, |
170 | 162 | "outputs": [ |
171 | 163 | { |
|
174 | 166 | "7.5" |
175 | 167 | ] |
176 | 168 | }, |
177 | | - "execution_count": 10, |
| 169 | + "execution_count": 7, |
178 | 170 | "metadata": {}, |
179 | 171 | "output_type": "execute_result" |
180 | 172 | } |
|
185 | 177 | }, |
186 | 178 | { |
187 | 179 | "cell_type": "code", |
188 | | - "execution_count": 11, |
| 180 | + "execution_count": 8, |
189 | 181 | "metadata": {}, |
190 | 182 | "outputs": [], |
191 | 183 | "source": [ |
|
201 | 193 | }, |
202 | 194 | { |
203 | 195 | "cell_type": "code", |
204 | | - "execution_count": null, |
| 196 | + "execution_count": 9, |
205 | 197 | "metadata": { |
206 | 198 | "collapsed": true, |
207 | 199 | "jupyter": { |
|
220 | 212 | }, |
221 | 213 | { |
222 | 214 | "cell_type": "code", |
223 | | - "execution_count": null, |
| 215 | + "execution_count": 10, |
224 | 216 | "metadata": {}, |
225 | | - "outputs": [], |
| 217 | + "outputs": [ |
| 218 | + { |
| 219 | + "data": { |
| 220 | + "text/plain": [ |
| 221 | + "64.0" |
| 222 | + ] |
| 223 | + }, |
| 224 | + "execution_count": 10, |
| 225 | + "metadata": {}, |
| 226 | + "output_type": "execute_result" |
| 227 | + } |
| 228 | + ], |
226 | 229 | "source": [ |
227 | 230 | "square" |
228 | 231 | ] |
|
236 | 239 | }, |
237 | 240 | { |
238 | 241 | "cell_type": "code", |
239 | | - "execution_count": null, |
| 242 | + "execution_count": 11, |
240 | 243 | "metadata": {}, |
241 | | - "outputs": [], |
| 244 | + "outputs": [ |
| 245 | + { |
| 246 | + "data": { |
| 247 | + "application/vnd.jupyter.widget-view+json": { |
| 248 | + "model_id": "228804fff5374f7a954838e144d7e8e3", |
| 249 | + "version_major": 2, |
| 250 | + "version_minor": 0 |
| 251 | + }, |
| 252 | + "text/plain": [ |
| 253 | + "VBox(children=(FloatSlider(value=8.0, description='Input:', max=10.0, min=5.0), FloatText(value=8.0, descripti…" |
| 254 | + ] |
| 255 | + }, |
| 256 | + "metadata": {}, |
| 257 | + "output_type": "display_data" |
| 258 | + } |
| 259 | + ], |
242 | 260 | "source": [ |
243 | 261 | "text = FloatText(description='Value')\n", |
244 | 262 | "link((slider, 'value'), (text, 'value'))\n", |
|
253 | 271 | "\n", |
254 | 272 | "Jupyter widgets forms a framework for representing python objects interactively. Some large open-source interactive controls based on Jupyter widgets include:\n", |
255 | 273 | "\n", |
256 | | - " - bqplot - 2d plotting library\n", |
257 | | - " - pythreejs - low-level 3d graphics library\n", |
258 | | - " - ipyvolume - high-level 3d graphics library\n", |
259 | | - " - ipyleaflet - maps" |
| 274 | + " - [bqplot](https://github.com/bloomberg/bqplot) - 2d plotting library\n", |
| 275 | + " - [pythreejs](https://github.com/jupyter-widgets/pythreejs) - low-level 3d graphics library\n", |
| 276 | + " - [ipyvolume](https://github.com/maartenbreddels/ipyvolume) - high-level 3d graphics library\n", |
| 277 | + " - [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) - maps" |
260 | 278 | ] |
261 | 279 | } |
262 | 280 | ], |
|
0 commit comments