##// END OF EJS Templates
remove notebook examples...
Min RK -
r21637:d1ce07b2
parent child
Show More
1 NO CONTENT: file renamed from examples/Notebook/Importing Notebooks.ipynb to examples/IPython Kernel/Importing Notebooks.ipynb
NO CONTENT: file renamed from examples/Notebook/Importing Notebooks.ipynb to examples/IPython Kernel/Importing Notebooks.ipynb
@@ -61,7 +61,8
61 "* [Background Jobs](Background Jobs.ipynb)\n",
61 "* [Background Jobs](Background Jobs.ipynb)\n",
62 "* [Trapezoid Rule](Trapezoid Rule.ipynb)\n",
62 "* [Trapezoid Rule](Trapezoid Rule.ipynb)\n",
63 "* [SymPy](SymPy.ipynb)\n",
63 "* [SymPy](SymPy.ipynb)\n",
64 "* [Raw Input in the Notebook](Raw Input in the Notebook.ipynb)"
64 "* [Raw Input in the Notebook](Raw Input in the Notebook.ipynb)\n",
65 "* [Importing Notebooks](Importing Notebooks.ipynb)"
65 ]
66 ]
66 },
67 },
67 {
68 {
@@ -190,7 +191,7
190 "name": "python",
191 "name": "python",
191 "nbconvert_exporter": "python",
192 "nbconvert_exporter": "python",
192 "pygments_lexer": "ipython3",
193 "pygments_lexer": "ipython3",
193 "version": "3.4.2"
194 "version": "3.4.3"
194 }
195 }
195 },
196 },
196 "nbformat": 4,
197 "nbformat": 4,
1 NO CONTENT: file renamed from examples/Notebook/nbpackage/__init__.py to examples/IPython Kernel/nbpackage/__init__.py
NO CONTENT: file renamed from examples/Notebook/nbpackage/__init__.py to examples/IPython Kernel/nbpackage/__init__.py
1 NO CONTENT: file renamed from examples/Notebook/nbpackage/mynotebook.ipynb to examples/IPython Kernel/nbpackage/mynotebook.ipynb
NO CONTENT: file renamed from examples/Notebook/nbpackage/mynotebook.ipynb to examples/IPython Kernel/nbpackage/mynotebook.ipynb
1 NO CONTENT: file renamed from examples/Notebook/nbpackage/nbs/__init__.py to examples/IPython Kernel/nbpackage/nbs/__init__.py
NO CONTENT: file renamed from examples/Notebook/nbpackage/nbs/__init__.py to examples/IPython Kernel/nbpackage/nbs/__init__.py
1 NO CONTENT: file renamed from examples/Notebook/nbpackage/nbs/other.ipynb to examples/IPython Kernel/nbpackage/nbs/other.ipynb
NO CONTENT: file renamed from examples/Notebook/nbpackage/nbs/other.ipynb to examples/IPython Kernel/nbpackage/nbs/other.ipynb
@@ -33,10 +33,6
33 "metadata": {},
33 "metadata": {},
34 "source": [
34 "source": [
35 "* [IPython Kernel](IPython Kernel/Index.ipynb): IPython's core syntax and command line features available in all frontends\n",
35 "* [IPython Kernel](IPython Kernel/Index.ipynb): IPython's core syntax and command line features available in all frontends\n",
36 "* [Notebook](Notebook/Index.ipynb): The IPython Notebook frontend\n",
37 "* [Interactive Widgets](Interactive Widgets/Index.ipynb): Interactive JavaScript/HTML widgets and `interact`\n",
38 "* [Parallel Computing](Parallel Computing/Index.ipynb): IPython's library for interactive parallel computing\n",
39 "* [Customization](Customization/Index.ipynb): How to configure IPython and customize it with magics, extensions, etc.\n",
40 "* [Embedding](Embedding/Index.ipynb): Embedding and reusing IPython's components into other applications\n"
36 "* [Embedding](Embedding/Index.ipynb): Embedding and reusing IPython's components into other applications\n"
41 ]
37 ]
42 }
38 }
@@ -57,7 +53,7
57 "name": "python",
53 "name": "python",
58 "nbconvert_exporter": "python",
54 "nbconvert_exporter": "python",
59 "pygments_lexer": "ipython3",
55 "pygments_lexer": "ipython3",
60 "version": "3.4.2"
56 "version": "3.4.3"
61 }
57 }
62 },
58 },
63 "nbformat": 4,
59 "nbformat": 4,
@@ -1,120 +0,0
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# Exploring Beat Frequencies using the `Audio` Object"
8 ]
9 },
10 {
11 "cell_type": "markdown",
12 "metadata": {},
13 "source": [
14 "This example uses the `Audio` object and Matplotlib to explore the phenomenon of beat frequencies."
15 ]
16 },
17 {
18 "cell_type": "code",
19 "execution_count": null,
20 "metadata": {
21 "collapsed": false
22 },
23 "outputs": [],
24 "source": [
25 "%matplotlib inline\n",
26 "import matplotlib.pyplot as plt\n",
27 "import numpy as np"
28 ]
29 },
30 {
31 "cell_type": "code",
32 "execution_count": null,
33 "metadata": {
34 "collapsed": false
35 },
36 "outputs": [],
37 "source": [
38 "from IPython.html.widgets import interactive\n",
39 "from IPython.display import Audio, display\n",
40 "import numpy as np"
41 ]
42 },
43 {
44 "cell_type": "code",
45 "execution_count": null,
46 "metadata": {
47 "collapsed": false
48 },
49 "outputs": [],
50 "source": [
51 "def beat_freq(f1=220.0, f2=224.0):\n",
52 " max_time = 3\n",
53 " rate = 8000\n",
54 " times = np.linspace(0,max_time,rate*max_time)\n",
55 " signal = np.sin(2*np.pi*f1*times) + np.sin(2*np.pi*f2*times)\n",
56 " print(f1, f2, abs(f1-f2))\n",
57 " display(Audio(data=signal, rate=rate))\n",
58 " return signal"
59 ]
60 },
61 {
62 "cell_type": "code",
63 "execution_count": null,
64 "metadata": {
65 "collapsed": false
66 },
67 "outputs": [],
68 "source": [
69 "v = interactive(beat_freq, f1=(200.0,300.0), f2=(200.0,300.0))\n",
70 "display(v)"
71 ]
72 },
73 {
74 "cell_type": "code",
75 "execution_count": null,
76 "metadata": {
77 "collapsed": false
78 },
79 "outputs": [],
80 "source": [
81 "v.kwargs"
82 ]
83 },
84 {
85 "cell_type": "code",
86 "execution_count": null,
87 "metadata": {
88 "collapsed": false
89 },
90 "outputs": [],
91 "source": [
92 "f1, f2 = v.children\n",
93 "f1.value = 255\n",
94 "f2.value = 260\n",
95 "plt.plot(v.result[0:6000])"
96 ]
97 }
98 ],
99 "metadata": {
100 "kernelspec": {
101 "display_name": "Python 3",
102 "language": "python",
103 "name": "python3"
104 },
105 "language_info": {
106 "codemirror_mode": {
107 "name": "ipython",
108 "version": 3
109 },
110 "file_extension": ".py",
111 "mimetype": "text/x-python",
112 "name": "python",
113 "nbconvert_exporter": "python",
114 "pygments_lexer": "ipython3",
115 "version": "3.4.0"
116 }
117 },
118 "nbformat": 4,
119 "nbformat_minor": 0
120 }
This diff has been collapsed as it changes many lines, (793 lines changed) Show them Hide them
@@ -1,793 +0,0
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "[Index](Index.ipynb) - [Back](Widget Styling.ipynb)"
8 ]
9 },
10 {
11 "cell_type": "code",
12 "execution_count": null,
13 "metadata": {
14 "collapsed": false
15 },
16 "outputs": [],
17 "source": [
18 "from __future__ import print_function # For py 2.7 compat"
19 ]
20 },
21 {
22 "cell_type": "markdown",
23 "metadata": {
24 "slideshow": {
25 "slide_type": "slide"
26 }
27 },
28 "source": [
29 "# Building a Custom Widget"
30 ]
31 },
32 {
33 "cell_type": "markdown",
34 "metadata": {},
35 "source": [
36 "The widget framework is built **on top of the Comm framework** (short for communication). The Comm framework is a framework that **allows you send/receive JSON messages** to/from the front-end (as seen below).\n",
37 "\n",
38 "![Widget layer](images/WidgetArch.png)\n",
39 "\n",
40 "To create a custom widget, you need to **define the widget both in the back-end and in the front-end**. "
41 ]
42 },
43 {
44 "cell_type": "markdown",
45 "metadata": {
46 "slideshow": {
47 "slide_type": "slide"
48 }
49 },
50 "source": [
51 "# Building a Custom Widget"
52 ]
53 },
54 {
55 "cell_type": "markdown",
56 "metadata": {},
57 "source": [
58 "To get started, you'll create a **simple hello world widget**. Later you'll build on this foundation to make more complex widgets."
59 ]
60 },
61 {
62 "cell_type": "markdown",
63 "metadata": {
64 "slideshow": {
65 "slide_type": "slide"
66 }
67 },
68 "source": [
69 "## Back-end (Python)"
70 ]
71 },
72 {
73 "cell_type": "markdown",
74 "metadata": {},
75 "source": [
76 "### DOMWidget and Widget"
77 ]
78 },
79 {
80 "cell_type": "markdown",
81 "metadata": {},
82 "source": [
83 "To define a widget, you must inherit from the **Widget or DOMWidget** base class. If you intend for your widget to be **displayed in the IPython notebook**, you'll need to **inherit from the DOMWidget**. The DOMWidget class itself inherits from the Widget class. The Widget class is useful for cases in which the **Widget is not meant to be displayed directly in the notebook**, but **instead as a child of another rendering environment**. For example, if you wanted to create a three.js widget (a popular WebGL library), you would implement the rendering window as a DOMWidget and any 3D objects or lights meant to be rendered in that window as Widgets."
84 ]
85 },
86 {
87 "cell_type": "markdown",
88 "metadata": {
89 "slideshow": {
90 "slide_type": "slide"
91 }
92 },
93 "source": [
94 "### _view_name"
95 ]
96 },
97 {
98 "cell_type": "markdown",
99 "metadata": {},
100 "source": [
101 "Inheriting from the DOMWidget does not tell the widget framework what front-end widget to associate with your back-end widget. Instead, you must tell it yourself by defining a **specially named Traitlet, `_view_name`** (as seen below)."
102 ]
103 },
104 {
105 "cell_type": "code",
106 "execution_count": null,
107 "metadata": {
108 "collapsed": false
109 },
110 "outputs": [],
111 "source": [
112 "from IPython.html import widgets\n",
113 "from traitlets import Unicode\n",
114 "\n",
115 "class HelloWidget(widgets.DOMWidget):\n",
116 " _view_name = Unicode('HelloView', sync=True)"
117 ]
118 },
119 {
120 "cell_type": "markdown",
121 "metadata": {
122 "slideshow": {
123 "slide_type": "slide"
124 }
125 },
126 "source": [
127 "### sync=True traitlets"
128 ]
129 },
130 {
131 "cell_type": "markdown",
132 "metadata": {},
133 "source": [
134 "**Traitlets is** an IPython library for defining **type-safe properties** on configurable objects. For this tutorial you do not need to worry about the *configurable* piece of the traitlets machinery. The **`sync=True` keyword argument** tells the widget framework to **handle synchronizing that value to the front-end**. Without `sync=True`, the front-end would have no knowledge of `_view_name`."
135 ]
136 },
137 {
138 "cell_type": "markdown",
139 "metadata": {
140 "slideshow": {
141 "slide_type": "slide"
142 }
143 },
144 "source": [
145 "### Other traitlet types"
146 ]
147 },
148 {
149 "cell_type": "markdown",
150 "metadata": {},
151 "source": [
152 "Unicode, used for _view_name, is not the only Traitlet type, there are many more some of which are listed below: \n",
153 "\n",
154 "- Any\n",
155 "- Bool\n",
156 "- Bytes\n",
157 "- CBool\n",
158 "- CBytes\n",
159 "- CComplex\n",
160 "- CFloat\n",
161 "- CInt\n",
162 "- CLong\n",
163 "- CRegExp\n",
164 "- CUnicode\n",
165 "- CaselessStrEnum\n",
166 "- Complex\n",
167 "- Dict\n",
168 "- DottedObjectName\n",
169 "- Enum\n",
170 "- Float\n",
171 "- FunctionType\n",
172 "- Instance\n",
173 "- InstanceType\n",
174 "- Int\n",
175 "- List\n",
176 "- Long\n",
177 "- Set\n",
178 "- TCPAddress\n",
179 "- Tuple\n",
180 "- Type\n",
181 "- Unicode\n",
182 "- Union\n",
183 "\n",
184 "\n",
185 "**Not all of these traitlets can be synchronized** across the network, **only the JSON-able** traits and **Widget instances** will be synchronized."
186 ]
187 },
188 {
189 "cell_type": "markdown",
190 "metadata": {
191 "slideshow": {
192 "slide_type": "slide"
193 }
194 },
195 "source": [
196 "## Front-end (JavaScript)"
197 ]
198 },
199 {
200 "cell_type": "markdown",
201 "metadata": {},
202 "source": [
203 "### Models and views"
204 ]
205 },
206 {
207 "cell_type": "markdown",
208 "metadata": {},
209 "source": [
210 "The IPython widget framework front-end relies heavily on [Backbone.js](http://backbonejs.org/). **Backbone.js is an MVC (model view controller) framework**. Widgets defined in the back-end are automatically **synchronized with generic Backbone.js models** in the front-end. The traitlets are added to the front-end instance **automatically on first state push**. The **`_view_name` trait** that you defined earlier is used by the widget framework to create the corresponding Backbone.js view and **link that view to the model**."
211 ]
212 },
213 {
214 "cell_type": "markdown",
215 "metadata": {
216 "slideshow": {
217 "slide_type": "slide"
218 }
219 },
220 "source": [
221 "### Import the WidgetManager"
222 ]
223 },
224 {
225 "cell_type": "markdown",
226 "metadata": {},
227 "source": [
228 "You first need to **import the `widget` and `manager` modules**. You will use the manager later to register your view by name (the same name you used in the back-end). To import the modules, use the `require` method of [require.js](http://requirejs.org/) (as seen below).\n"
229 ]
230 },
231 {
232 "cell_type": "code",
233 "execution_count": null,
234 "metadata": {
235 "collapsed": false
236 },
237 "outputs": [],
238 "source": [
239 "%%javascript\n",
240 "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
241 " \n",
242 "});"
243 ]
244 },
245 {
246 "cell_type": "markdown",
247 "metadata": {
248 "slideshow": {
249 "slide_type": "slide"
250 }
251 },
252 "source": [
253 "### Define the view"
254 ]
255 },
256 {
257 "cell_type": "markdown",
258 "metadata": {},
259 "source": [
260 "Next define your widget view class. **Inherit from the `DOMWidgetView`** by using the `.extend` method. Register the view class with the widget manager by calling **`.register_widget_view`**. The **first parameter is the widget view name** (`_view_name` that you defined earlier in Python) and the **second is a handle to the class type**."
261 ]
262 },
263 {
264 "cell_type": "code",
265 "execution_count": null,
266 "metadata": {
267 "collapsed": false
268 },
269 "outputs": [],
270 "source": [
271 "%%javascript\n",
272 "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
273 " \n",
274 " // Define the HelloView\n",
275 " var HelloView = widget.DOMWidgetView.extend({\n",
276 " \n",
277 " });\n",
278 " \n",
279 " // Register the HelloView with the widget manager.\n",
280 " manager.WidgetManager.register_widget_view('HelloView', HelloView);\n",
281 "});"
282 ]
283 },
284 {
285 "cell_type": "markdown",
286 "metadata": {
287 "slideshow": {
288 "slide_type": "slide"
289 }
290 },
291 "source": [
292 "### Render method"
293 ]
294 },
295 {
296 "cell_type": "markdown",
297 "metadata": {},
298 "source": [
299 "Lastly, **override the base `render` method** of the view to define custom rendering logic. A handle to the widget's default div element can be acquired via **`this.$el`**. The `$el` property is a **[jQuery](http://jquery.com/) object handle** (which can be thought of as a supercharged version of the normal DOM element's handle)."
300 ]
301 },
302 {
303 "cell_type": "code",
304 "execution_count": null,
305 "metadata": {
306 "collapsed": false
307 },
308 "outputs": [],
309 "source": [
310 "%%javascript\n",
311 "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
312 " \n",
313 " var HelloView = widget.DOMWidgetView.extend({\n",
314 " \n",
315 " // Render the view.\n",
316 " render: function(){ \n",
317 " this.$el.text('Hello World!'); \n",
318 " },\n",
319 " });\n",
320 " \n",
321 " manager.WidgetManager.register_widget_view('HelloView', HelloView);\n",
322 "});"
323 ]
324 },
325 {
326 "cell_type": "markdown",
327 "metadata": {
328 "slideshow": {
329 "slide_type": "slide"
330 }
331 },
332 "source": [
333 "## Test"
334 ]
335 },
336 {
337 "cell_type": "markdown",
338 "metadata": {},
339 "source": [
340 "You should be able to display your widget just like any other widget now."
341 ]
342 },
343 {
344 "cell_type": "code",
345 "execution_count": null,
346 "metadata": {
347 "collapsed": false
348 },
349 "outputs": [],
350 "source": [
351 "HelloWidget()"
352 ]
353 },
354 {
355 "cell_type": "markdown",
356 "metadata": {
357 "slideshow": {
358 "slide_type": "slide"
359 }
360 },
361 "source": [
362 "## Making the widget stateful"
363 ]
364 },
365 {
366 "cell_type": "markdown",
367 "metadata": {},
368 "source": [
369 "There is not much that you can do with the above example that you can't do with the IPython display framework. To change this, you will make the widget stateful. Instead of displaying a static \"hello world\" message, it will **display a string set by the back-end**. First you need to **add a traitlet in the back-end**. Use the name of **`value` to stay consistent** with the rest of the widget framework and to **allow your widget to be used with interact**."
370 ]
371 },
372 {
373 "cell_type": "code",
374 "execution_count": null,
375 "metadata": {
376 "collapsed": false
377 },
378 "outputs": [],
379 "source": [
380 "class HelloWidget(widgets.DOMWidget):\n",
381 " _view_name = Unicode('HelloView', sync=True)\n",
382 " value = Unicode('Hello World!', sync=True)"
383 ]
384 },
385 {
386 "cell_type": "markdown",
387 "metadata": {
388 "slideshow": {
389 "slide_type": "slide"
390 }
391 },
392 "source": [
393 "### Accessing the model from the view"
394 ]
395 },
396 {
397 "cell_type": "markdown",
398 "metadata": {},
399 "source": [
400 "To access the model associate with a view instance, use the **`model` property** of the view. **`get` and `set`** methods are used to interact with the Backbone model. **`get` is trivial**, however you have to **be careful when using `set`**. **After calling the model `set`** you need call the **view's `touch` method**. This associates the `set` operation with a particular view so **output will be routed to the correct cell**. The model also has a **`on` method** which allows you to listen to events triggered by the model (like value changes)."
401 ]
402 },
403 {
404 "cell_type": "markdown",
405 "metadata": {
406 "slideshow": {
407 "slide_type": "slide"
408 }
409 },
410 "source": [
411 "### Rendering model contents"
412 ]
413 },
414 {
415 "cell_type": "markdown",
416 "metadata": {},
417 "source": [
418 "By **replacing the string literal with a call to `model.get`**, the view will now display the **value of the back-end upon display**. However, it will not update itself to a new value when the value changes."
419 ]
420 },
421 {
422 "cell_type": "code",
423 "execution_count": null,
424 "metadata": {
425 "collapsed": false
426 },
427 "outputs": [],
428 "source": [
429 "%%javascript\n",
430 "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
431 " \n",
432 " var HelloView = widget.DOMWidgetView.extend({\n",
433 " \n",
434 " render: function(){ \n",
435 " this.$el.text(this.model.get('value')); \n",
436 " },\n",
437 " });\n",
438 " \n",
439 " manager.WidgetManager.register_widget_view('HelloView', HelloView);\n",
440 "});"
441 ]
442 },
443 {
444 "cell_type": "markdown",
445 "metadata": {
446 "slideshow": {
447 "slide_type": "slide"
448 }
449 },
450 "source": [
451 "### Dynamic updates"
452 ]
453 },
454 {
455 "cell_type": "markdown",
456 "metadata": {},
457 "source": [
458 "To get the view to **update itself dynamically**, register a function to update the view's value when the model's `value` property changes. This can be done using the **`model.on` method**. The `on` method takes three parameters, an event name, callback handle, and callback context. The Backbone **event named `change`** will fire whenever the model changes. By **appending `:value`** to it, you tell Backbone to only listen to the change event of the `value` property (as seen below)."
459 ]
460 },
461 {
462 "cell_type": "code",
463 "execution_count": null,
464 "metadata": {
465 "collapsed": false
466 },
467 "outputs": [],
468 "source": [
469 "%%javascript\n",
470 "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
471 " \n",
472 " var HelloView = widget.DOMWidgetView.extend({\n",
473 " \n",
474 " render: function(){ \n",
475 " this.value_changed();\n",
476 " this.model.on('change:value', this.value_changed, this);\n",
477 " },\n",
478 " \n",
479 " value_changed: function() {\n",
480 " this.$el.text(this.model.get('value')); \n",
481 " },\n",
482 " });\n",
483 " \n",
484 " manager.WidgetManager.register_widget_view('HelloView', HelloView);\n",
485 "});"
486 ]
487 },
488 {
489 "cell_type": "markdown",
490 "metadata": {
491 "slideshow": {
492 "slide_type": "slide"
493 }
494 },
495 "source": [
496 "## Test"
497 ]
498 },
499 {
500 "cell_type": "code",
501 "execution_count": null,
502 "metadata": {
503 "collapsed": false
504 },
505 "outputs": [],
506 "source": [
507 "w = HelloWidget()\n",
508 "w"
509 ]
510 },
511 {
512 "cell_type": "code",
513 "execution_count": null,
514 "metadata": {
515 "collapsed": false
516 },
517 "outputs": [],
518 "source": [
519 "w.value = 'test'"
520 ]
521 },
522 {
523 "cell_type": "markdown",
524 "metadata": {
525 "slideshow": {
526 "slide_type": "slide"
527 }
528 },
529 "source": [
530 "# Finishing"
531 ]
532 },
533 {
534 "cell_type": "markdown",
535 "metadata": {},
536 "source": [
537 "## Bidirectional communication"
538 ]
539 },
540 {
541 "cell_type": "markdown",
542 "metadata": {},
543 "source": [
544 "The examples above dump the value directly into the DOM. There is no way for you to interact with this dumped data in the front-end. To create an example that **accepts input**, you will have to do something more than blindly dumping the contents of value into the DOM. In this part of the tutorial, you will **use a jQuery spinner** to display and accept input in the front-end. IPython currently lacks a spinner implementation so this widget will be unique."
545 ]
546 },
547 {
548 "cell_type": "markdown",
549 "metadata": {
550 "slideshow": {
551 "slide_type": "slide"
552 }
553 },
554 "source": [
555 "### Update the Python code"
556 ]
557 },
558 {
559 "cell_type": "markdown",
560 "metadata": {},
561 "source": [
562 "You will need to change the type of the **value traitlet to `Int`**. It also makes sense to **change the name of the widget** to something more appropriate, like `SpinnerWidget`."
563 ]
564 },
565 {
566 "cell_type": "code",
567 "execution_count": null,
568 "metadata": {
569 "collapsed": false
570 },
571 "outputs": [],
572 "source": [
573 "from traitlets import CInt\n",
574 "class SpinnerWidget(widgets.DOMWidget):\n",
575 " _view_name = Unicode('SpinnerView', sync=True)\n",
576 " value = CInt(0, sync=True)"
577 ]
578 },
579 {
580 "cell_type": "markdown",
581 "metadata": {
582 "slideshow": {
583 "slide_type": "slide"
584 }
585 },
586 "source": [
587 "### Updating the Javascript code"
588 ]
589 },
590 {
591 "cell_type": "markdown",
592 "metadata": {},
593 "source": [
594 "The [jQuery docs for the spinner control](https://jqueryui.com/spinner/) say to use **`.spinner` to create a spinner** in an element. Calling **`.spinner` on `$el` will create a spinner inside `$el`**. Make sure to **update the widget name here too** so it's the same as `_view_name` in the back-end."
595 ]
596 },
597 {
598 "cell_type": "code",
599 "execution_count": null,
600 "metadata": {
601 "collapsed": false
602 },
603 "outputs": [],
604 "source": [
605 "%%javascript\n",
606 "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
607 " \n",
608 " var SpinnerView = widget.DOMWidgetView.extend({\n",
609 " \n",
610 " render: function(){ \n",
611 " \n",
612 " // jQuery code to create a spinner and append it to $el\n",
613 " this.$input = $('<input />');\n",
614 " this.$el.append(this.$input);\n",
615 " this.$spinner = this.$input.spinner({\n",
616 " change: function( event, ui ) {}\n",
617 " });\n",
618 " \n",
619 " this.value_changed();\n",
620 " this.model.on('change:value', this.value_changed, this);\n",
621 " },\n",
622 " \n",
623 " value_changed: function() {\n",
624 " \n",
625 " },\n",
626 " });\n",
627 " \n",
628 " manager.WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n",
629 "});"
630 ]
631 },
632 {
633 "cell_type": "markdown",
634 "metadata": {
635 "slideshow": {
636 "slide_type": "slide"
637 }
638 },
639 "source": [
640 "### Getting and setting the value"
641 ]
642 },
643 {
644 "cell_type": "markdown",
645 "metadata": {},
646 "source": [
647 "To **set the value of the spinner on update from the back-end**, you need to use **jQuery's `spinner` API**. `spinner.spinner('value', new)` will set the value of the spinner. Add that code to the **`value_changed` method** to make the spinner **update with the value stored in the back-end((. Using jQuery's spinner API, you can add a function to handle the **spinner `change` event** by passing it in when constructing the spinner. Inside the `change` event, call **`model.set`** to set the value and then **`touch`** to inform the framework that this view was the view that caused the change to the model. **Note: The `var that = this;` is a JavaScript trick to pass the current context into closures.**"
648 ]
649 },
650 {
651 "cell_type": "code",
652 "execution_count": null,
653 "metadata": {
654 "collapsed": false
655 },
656 "outputs": [],
657 "source": [
658 "%%javascript\n",
659 "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
660