j1-template 2022.4.1 → 2022.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/_includes/themes/j1/layouts/content_generator_article_navigator.html +1 -1
  3. data/_includes/themes/j1/layouts/content_generator_blog_archive.html +1 -1
  4. data/_includes/themes/j1/layouts/content_generator_news_panel_posts.html +1 -1
  5. data/assets/themes/j1/adapter/js/nbinteract.js +11 -0
  6. data/assets/themes/j1/modules/bokeh/README.md +380 -0
  7. data/assets/themes/j1/modules/bokeh/js/v2.4.3/bokeh.min.js +596 -0
  8. data/assets/themes/j1/modules/nbInteract/css/theme/uno/nbinteract-core.css +7 -0
  9. data/assets/themes/j1/modules/nbInteract/css/theme/uno/nbinteract-core.min.css +1 -1
  10. data/assets/themes/j1/modules/vega/js/vega/LICENSE +27 -0
  11. data/assets/themes/j1/modules/vega/js/vega/README.md +42 -0
  12. data/assets/themes/j1/modules/vega/js/vega/vega-core.js +34550 -0
  13. data/assets/themes/j1/modules/vega/js/vega/vega-core.min.js +2 -0
  14. data/assets/themes/j1/modules/vega/js/vega/vega-core.min.js.map +1 -0
  15. data/assets/themes/j1/modules/vega/js/vega/vega.js +49095 -0
  16. data/assets/themes/j1/modules/vega/js/vega/vega.min.js +2 -0
  17. data/assets/themes/j1/modules/vega/js/vega/vega.min.js.map +1 -0
  18. data/assets/themes/j1/modules/vega/js/vega-embed/LICENSE +27 -0
  19. data/assets/themes/j1/modules/vega/js/vega-embed/README.md +230 -0
  20. data/assets/themes/j1/modules/vega/js/vega-embed/vega-embed.js +6607 -0
  21. data/assets/themes/j1/modules/vega/js/vega-embed/vega-embed.js.map +1 -0
  22. data/assets/themes/j1/modules/vega/js/vega-embed/vega-embed.min.js +21 -0
  23. data/assets/themes/j1/modules/vega/js/vega-embed/vega-embed.min.js.map +1 -0
  24. data/assets/themes/j1/modules/vega/js/vega-lite/LICENSE +27 -0
  25. data/assets/themes/j1/modules/vega/js/vega-lite/README.md +34 -0
  26. data/assets/themes/j1/modules/vega/js/vega-lite/vega-lite-schema.json +30999 -0
  27. data/assets/themes/j1/modules/vega/js/vega-lite/vega-lite.js +24585 -0
  28. data/assets/themes/j1/modules/vega/js/vega-lite/vega-lite.js.map +1 -0
  29. data/assets/themes/j1/modules/vega/js/vega-lite/vega-lite.min.js +2 -0
  30. data/assets/themes/j1/modules/vega/js/vega-lite/vega-lite.min.js.map +1 -0
  31. data/lib/j1/version.rb +1 -1
  32. data/lib/starter_web/Gemfile +1 -1
  33. data/lib/starter_web/_config.yml +1 -1
  34. data/lib/starter_web/_data/modules/defaults/nbinteract.yml +1 -1
  35. data/lib/starter_web/_data/modules/navigator_menu.yml +40 -23
  36. data/lib/starter_web/_data/modules/nbinteract.yml +314 -295
  37. data/lib/starter_web/_data/resources.yml +101 -0
  38. data/lib/starter_web/_plugins/lunr_index.rb +1 -1
  39. data/lib/starter_web/assets/images/modules/attics/wrongtog-1920x1280.jpg +0 -0
  40. data/lib/starter_web/assets/images/modules/attics/yellow-cactus-1920x1280.jpg +0 -0
  41. data/lib/starter_web/assets/images/modules/icons/bokeh/bokeh-32x32.ico +0 -0
  42. data/lib/starter_web/assets/images/modules/icons/bokeh/bokeh.ico +0 -0
  43. data/lib/starter_web/assets/images/modules/icons/bokeh/logo-160x160.png +0 -0
  44. data/lib/starter_web/package.json +1 -1
  45. data/lib/starter_web/pages/public/jupyter/examples/{j1-circular-times-table.adoc → distributed/j1-circular-times-table.adoc} +7 -2
  46. data/lib/starter_web/pages/public/jupyter/examples/{j1-interactive-widgets.adoc → distributed/j1-common-used-widgets.adoc} +14 -6
  47. data/lib/starter_web/pages/public/jupyter/examples/{j1-odes-in-python.adoc → distributed/j1-odes-in-python.adoc} +7 -2
  48. data/lib/starter_web/pages/public/jupyter/examples/{j1_climate-change-forecast.adoc → localized/j1_climate-change-forecast.adoc} +10 -5
  49. data/lib/starter_web/pages/public/jupyter/where_to_go.adoc +239 -0
  50. data/lib/starter_web/pages/public/learn/where_to_go.adoc +23 -7
  51. data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
  52. data/lib/starter_web/utilsrv/package.json +1 -1
  53. metadata +35 -30
  54. data/lib/starter_web/pages/public/jupyter/docs/_includes/attributes.asciidoc +0 -58
  55. data/lib/starter_web/pages/public/jupyter/docs/_includes/documents/j1_docs_example_static.asciidoc +0 -232
  56. data/lib/starter_web/pages/public/jupyter/docs/j1-nbinteract-doc.adoc +0 -563
  57. data/lib/starter_web/pages/public/jupyter/docs/nbi-widget-manual.adoc +0 -465
  58. data/lib/starter_web/pages/public/jupyter/docs/nbinteract-doc.adoc +0 -473
  59. data/lib/starter_web/pages/public/jupyter/examples/j1-testing-plotly.adoc +0 -94
  60. data/lib/starter_web/pages/public/jupyter/notebooks/j1/.ipynb_checkpoints/j1_circular_times_table-checkpoint.ipynb +0 -12387
  61. data/lib/starter_web/pages/public/jupyter/notebooks/j1/.ipynb_checkpoints/j1_climate_change_forecast-checkpoint.ipynb +0 -1058
  62. data/lib/starter_web/pages/public/jupyter/notebooks/j1/.ipynb_checkpoints/j1_docs_example_dynamic-checkpoint.ipynb +0 -14478
  63. data/lib/starter_web/pages/public/jupyter/notebooks/j1/.ipynb_checkpoints/j1_interactive_widgets-checkpoint.ipynb +0 -738
  64. data/lib/starter_web/pages/public/jupyter/notebooks/j1/.ipynb_checkpoints/j1_ode_selected-checkpoint.ipynb +0 -14478
  65. data/lib/starter_web/pages/public/jupyter/notebooks/j1/.ipynb_checkpoints/j1_odes_in_python-checkpoint.ipynb +0 -15227
  66. data/lib/starter_web/pages/public/jupyter/notebooks/j1/factor_by_factor.mp4 +0 -0
  67. data/lib/starter_web/pages/public/jupyter/notebooks/j1/line_by_line.mp4 +0 -0
  68. data/lib/starter_web/pages/public/jupyter/notebooks/j1/point_by_point.mp4 +0 -0
  69. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_examples_central_limit_theorem-checkpoint.ipynb +0 -247
  70. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_examples_variability_of_the_sample_mean-checkpoint.ipynb +0 -323
  71. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_recipes_graphing-checkpoint.ipynb +0 -387
  72. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_recipes_interactive_questions-checkpoint.ipynb +0 -185
  73. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_recipes_layout-checkpoint.ipynb +0 -384
  74. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_tutorial_interact-checkpoint.ipynb +0 -254
  75. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_tutorial_monty_hall-checkpoint.ipynb +0 -732
  76. data/lib/starter_web/pages/public/jupyter/services/binderhub.adoc +0 -564
  77. data/lib/starter_web/pages/public/jupyter/services/jupyterhub.adoc +0 -244
@@ -1,738 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "## Widgets from ipywidgets\n",
8
- "\n",
9
- "The library *ipywidgets*, also known as *jupyter-widgets*, are interactive\n",
10
- "HTML widgets for Jupyter notebooks and the IPython kernel. Notebooks come\n",
11
- "alive when interactive widgets are used. Users gain control of their data\n",
12
- "and can visualize changes in the data.\n"
13
- ]
14
- },
15
- {
16
- "cell_type": "code",
17
- "execution_count": 1,
18
- "metadata": {},
19
- "outputs": [],
20
- "source": [
21
- "import matplotlib.pyplot as plt\n",
22
- "import ipywidgets as widgets\n",
23
- "from ipywidgets import interact\n",
24
- "import nbinteract as nbi\n",
25
- "import numpy as np\n",
26
- "from numpy import arange,sin,pi"
27
- ]
28
- },
29
- {
30
- "cell_type": "markdown",
31
- "metadata": {},
32
- "source": [
33
- "### Base slider"
34
- ]
35
- },
36
- {
37
- "cell_type": "code",
38
- "execution_count": 2,
39
- "metadata": {},
40
- "outputs": [
41
- {
42
- "data": {
43
- "application/vnd.jupyter.widget-view+json": {
44
- "model_id": "f66db90b8e2746a5bb4ce77b8a81738b",
45
- "version_major": 2,
46
- "version_minor": 0
47
- },
48
- "text/plain": [
49
- "interactive(children=(IntSlider(value=10, description='x', max=30, min=-10), Output()), _dom_classes=('widget-…"
50
- ]
51
- },
52
- "metadata": {},
53
- "output_type": "display_data"
54
- }
55
- ],
56
- "source": [
57
- "# Testing Interact from ipywidgets\n",
58
- "def square(x):\n",
59
- " return x * x\n",
60
- "\n",
61
- "interact(square, x=10);"
62
- ]
63
- },
64
- {
65
- "cell_type": "markdown",
66
- "metadata": {},
67
- "source": [
68
- "### Slider for widget control"
69
- ]
70
- },
71
- {
72
- "cell_type": "code",
73
- "execution_count": 3,
74
- "metadata": {},
75
- "outputs": [
76
- {
77
- "data": {
78
- "application/vnd.jupyter.widget-view+json": {
79
- "model_id": "674a3b8585444242843a165fd36a5cc2",
80
- "version_major": 2,
81
- "version_minor": 0
82
- },
83
- "text/plain": [
84
- "interactive(children=(FloatSlider(value=7.0685834705770345, description='xmax', max=12.566370614359172, min=1.…"
85
- ]
86
- },
87
- "metadata": {},
88
- "output_type": "display_data"
89
- }
90
- ],
91
- "source": [
92
- "# Definiere myplot-Funktion \n",
93
- "def myplot(xmax): \n",
94
- " x = arange(0, xmax, 0.01);y = sin(2*pi*x); \n",
95
- " plt.plot(x,y); \n",
96
- "\n",
97
- "# Erstelle ein Widget für den Plot mit Hilfe von interact \n",
98
- "interact(myplot, xmax = (pi/2,4*pi)); "
99
- ]
100
- },
101
- {
102
- "cell_type": "markdown",
103
- "metadata": {},
104
- "source": [
105
- "### Select box"
106
- ]
107
- },
108
- {
109
- "cell_type": "code",
110
- "execution_count": 4,
111
- "metadata": {},
112
- "outputs": [
113
- {
114
- "data": {
115
- "application/vnd.jupyter.widget-view+json": {
116
- "model_id": "63e03b8837e042ffb0fb36a48d95d85d",
117
- "version_major": 2,
118
- "version_minor": 0
119
- },
120
- "text/plain": [
121
- "interactive(children=(Dropdown(description='name', options=('Jim', 'Emma', 'Bond'), value='Jim'), Output()), _…"
122
- ]
123
- },
124
- "metadata": {},
125
- "output_type": "display_data"
126
- }
127
- ],
128
- "source": [
129
- "def say_my_name(name):\n",
130
- " \"\"\"\n",
131
- " Print the current widget value in short sentence\n",
132
- " \"\"\"\n",
133
- " print(f'My name is {name}')\n",
134
- " \n",
135
- "widgets.interact(say_my_name, name=[\"Jim\", \"Emma\", \"Bond\"]);"
136
- ]
137
- },
138
- {
139
- "cell_type": "markdown",
140
- "metadata": {},
141
- "source": [
142
- "### Combined widgets"
143
- ]
144
- },
145
- {
146
- "cell_type": "code",
147
- "execution_count": 5,
148
- "metadata": {},
149
- "outputs": [
150
- {
151
- "data": {
152
- "application/vnd.jupyter.widget-view+json": {
153
- "model_id": "81de367a58a445afa093b39819fdeb65",
154
- "version_major": 2,
155
- "version_minor": 0
156
- },
157
- "text/plain": [
158
- "interactive(children=(Dropdown(description='x', options=(0, 1, 2, 3), value=0), Output()), _dom_classes=('widg…"
159
- ]
160
- },
161
- "metadata": {},
162
- "output_type": "display_data"
163
- },
164
- {
165
- "data": {
166
- "application/vnd.jupyter.widget-view+json": {
167
- "model_id": "faba020a11b44537bf1b9f74339d8d52",
168
- "version_major": 2,
169
- "version_minor": 0
170
- },
171
- "text/plain": [
172
- "interactive(children=(IntSlider(value=5, description='x', max=10), Output()), _dom_classes=('widget-interact',…"
173
- ]
174
- },
175
- "metadata": {},
176
- "output_type": "display_data"
177
- },
178
- {
179
- "data": {
180
- "application/vnd.jupyter.widget-view+json": {
181
- "model_id": "f34cec7fb4a54934940f5d037440e9b7",
182
- "version_major": 2,
183
- "version_minor": 0
184
- },
185
- "text/plain": [
186
- "interactive(children=(FloatSlider(value=5.0, description='x', max=10.0, step=0.5), Output()), _dom_classes=('w…"
187
- ]
188
- },
189
- "metadata": {},
190
- "output_type": "display_data"
191
- },
192
- {
193
- "data": {
194
- "application/vnd.jupyter.widget-view+json": {
195
- "model_id": "b8b7d85b1759460dadc5568a014d7e80",
196
- "version_major": 2,
197
- "version_minor": 0
198
- },
199
- "text/plain": [
200
- "interactive(children=(Checkbox(value=True, description='x'), Output()), _dom_classes=('widget-interact',))"
201
- ]
202
- },
203
- "metadata": {},
204
- "output_type": "display_data"
205
- }
206
- ],
207
- "source": [
208
- "def say_something(x):\n",
209
- " \"\"\"\n",
210
- " Print the current widget value in short sentence\n",
211
- " \"\"\"\n",
212
- " print(f'Widget says: {x}')\n",
213
- " \n",
214
- "widgets.interact(say_something, x=[0, 1, 2, 3])\n",
215
- "widgets.interact(say_something, x=(0, 10, 1))\n",
216
- "widgets.interact(say_something, x=(0, 10, .5))\n",
217
- "_ = widgets.interact(say_something, x=True)"
218
- ]
219
- },
220
- {
221
- "cell_type": "markdown",
222
- "metadata": {},
223
- "source": [
224
- "### Complex widget configs"
225
- ]
226
- },
227
- {
228
- "cell_type": "code",
229
- "execution_count": 6,
230
- "metadata": {},
231
- "outputs": [
232
- {
233
- "data": {
234
- "application/vnd.jupyter.widget-view+json": {
235
- "model_id": "e0535be20c59454aa7529e40e0457f0e",
236
- "version_major": 2,
237
- "version_minor": 0
238
- },
239
- "text/plain": [
240
- "VBox(children=(IntSlider(value=5, description='slider', max=10), IntRangeSlider(value=(20, 40), description='r…"
241
- ]
242
- },
243
- "metadata": {},
244
- "output_type": "display_data"
245
- }
246
- ],
247
- "source": [
248
- "int_slider = widgets.IntSlider(\n",
249
- " value=5, \n",
250
- " min=0, max=10, step=1, \n",
251
- " description='slider'\n",
252
- ")\n",
253
- " \n",
254
- "int_range_slider = widgets.IntRangeSlider(\n",
255
- " value=(20, 40), \n",
256
- " min=0, max=100, step=2, \n",
257
- " description='range slider'\n",
258
- ")\n",
259
- " \n",
260
- "dropdown = widgets.Dropdown(\n",
261
- " value='feb', \n",
262
- " options=['jan', 'feb', 'mar', 'apr'], \n",
263
- " description='dropdown'\n",
264
- ")\n",
265
- " \n",
266
- "radiobuttons = widgets.RadioButtons(\n",
267
- " value='feb', \n",
268
- " options=['jan', 'feb', 'mar', 'apr'], \n",
269
- " description='radio buttons'\n",
270
- ")\n",
271
- " \n",
272
- "combobox = widgets.Combobox(\n",
273
- " placeholder='start typing... (e.g. L or o)',\n",
274
- " options=['Amsterdam', 'Athens', 'Lisbon', 'London', 'Ljubljana'], \n",
275
- " description='combo box'\n",
276
- ")\n",
277
- " \n",
278
- "checkbox = widgets.Checkbox(\n",
279
- " description='checkbox',\n",
280
- " value=True\n",
281
- ")\n",
282
- " \n",
283
- " \n",
284
- "# a VBox container to pack widgets vertically\n",
285
- "widgets.VBox(\n",
286
- " [\n",
287
- " int_slider, \n",
288
- " int_range_slider, \n",
289
- " dropdown, \n",
290
- " radiobuttons,\n",
291
- " checkbox,\n",
292
- " combobox,\n",
293
- " ]\n",
294
- ")\n"
295
- ]
296
- },
297
- {
298
- "cell_type": "markdown",
299
- "metadata": {},
300
- "source": [
301
- "### Connected sliders"
302
- ]
303
- },
304
- {
305
- "cell_type": "code",
306
- "execution_count": 7,
307
- "metadata": {},
308
- "outputs": [
309
- {
310
- "data": {
311
- "application/vnd.jupyter.widget-view+json": {
312
- "model_id": "1196c754303d48c8954b2ba783112516",
313
- "version_major": 2,
314
- "version_minor": 0
315
- },
316
- "text/plain": [
317
- "VBox(children=(IntSlider(value=5, description='slider 1', max=10), IntSlider(value=5, description='slider 2', …"
318
- ]
319
- },
320
- "metadata": {},
321
- "output_type": "display_data"
322
- }
323
- ],
324
- "source": [
325
- "sl1 = widgets.IntSlider(description='slider 1', min=0, max=10)\n",
326
- "sl2 = widgets.IntSlider(description='slider 2', min=0, max=10)\n",
327
- " \n",
328
- "link = widgets.link(\n",
329
- " (sl1, 'value'), \n",
330
- " (sl2, 'min')\n",
331
- ")\n",
332
- " \n",
333
- "sl1.value = 5\n",
334
- "widgets.VBox([sl1, sl2])"
335
- ]
336
- },
337
- {
338
- "cell_type": "markdown",
339
- "metadata": {},
340
- "source": [
341
- "## Widgets from nbinteract\n",
342
- "\n",
343
- "The library *nbinteract* comes with a set of functions that produce Javascript-based plots designed for interaction. The package combines the *ipywidgets* library and the *bqplot*\n",
344
- "plotting library to implement function-driven interfaces to interactive plotting.\n",
345
- "\n",
346
- "The nbinteract plotting methods use **ipywidgets** to generate and display widgets, inferring the widget type as needed. When a user interacts with a widget, a Python callback updates the visualization **without** a complete rerender. This noticeably lowers visualization update time compared to using ipywidgets alone to render static images."
347
- ]
348
- },
349
- {
350
- "cell_type": "markdown",
351
- "metadata": {},
352
- "source": [
353
- "### `nbinteract.hist`\n",
354
- "\n",
355
- "The widget hist generates a histogram that allows interaction with the parameters for the response function. The widget takes in a single response function. The response function returns the array of numerical values that will be shown in the histogram. The hist function allows interaction with the response function's parameters by specifying them as keyword arguments in the same format as ipywidgets.interact. Any argument that can be used for ipywidgets.interact can be used for hist.\n"
356
- ]
357
- },
358
- {
359
- "cell_type": "code",
360
- "execution_count": 8,
361
- "metadata": {},
362
- "outputs": [
363
- {
364
- "data": {
365
- "application/vnd.jupyter.widget-view+json": {
366
- "model_id": "5940507213474cf7a7a33b5e60f9d386",
367
- "version_major": 2,
368
- "version_minor": 0
369
- },
370
- "text/plain": [
371
- "VBox(children=(interactive(children=(IntSlider(value=5, description='mean', max=10), FloatSlider(value=1.0, de…"
372
- ]
373
- },
374
- "metadata": {},
375
- "output_type": "display_data"
376
- }
377
- ],
378
- "source": [
379
- "def hist_response_function(mean, sd, size=1000):\n",
380
- " '''\n",
381
- " Returns 1000 values picked at random from the normal\n",
382
- " distribution with the mean and SD given.\n",
383
- " '''\n",
384
- " return np.random.normal(loc=mean, scale=sd, size=1000)\n",
385
- "\n",
386
- "nbi.hist(hist_response_function, mean=(0, 10), sd=(0.2, 2.0, 0.2))"
387
- ]
388
- },
389
- {
390
- "cell_type": "markdown",
391
- "metadata": {},
392
- "source": [
393
- "### `nbinteract.bar`\n",
394
- "\n",
395
- "The widgetr bar generates an bar plot that allows interaction with the parameters for the response functions.\n",
396
- "\n",
397
- "The first two arguments of bar are response functions that return the x and y-axis data arrays, respectively. Either argument can be arrays themselves. Arguments for the response functions must be passed in as keyword arguments to bar in the format expected by interact. The response function for the y-axis data will be called with the x-axis data as its first argument.\n",
398
- "\n",
399
- "For example, in the bar plot below categories generates the categories to plot on the x-axis and heights generates the y-axis heights. The heights function uses the parameter xs which is the array of x-axis data points."
400
- ]
401
- },
402
- {
403
- "cell_type": "code",
404
- "execution_count": 18,
405
- "metadata": {},
406
- "outputs": [
407
- {
408
- "data": {
409
- "application/vnd.jupyter.widget-view+json": {
410
- "model_id": "467a66b0b3ba4036ae7ff52caea9af3c",
411
- "version_major": 2,
412
- "version_minor": 0
413
- },
414
- "text/plain": [
415
- "VBox(children=(interactive(children=(IntSlider(value=6, description='n', max=10, min=3), IntSlider(value=5, de…"
416
- ]
417
- },
418
- "metadata": {},
419
- "output_type": "display_data"
420
- }
421
- ],
422
- "source": [
423
- "def categories(n): \n",
424
- " return np.arange(n)\n",
425
- "\n",
426
- "def heights(xs, offset):\n",
427
- " return xs + offset\n",
428
- "\n",
429
- "opts = {\n",
430
- " 'ylim': (0, 20),\n",
431
- "}\n",
432
- "\n",
433
- "nbi.bar(categories, heights, n=(3, 10), offset=(1, 10), options=opts)"
434
- ]
435
- },
436
- {
437
- "cell_type": "markdown",
438
- "metadata": {},
439
- "source": [
440
- "### nbinteract.scatter_drag\n",
441
- "\n",
442
- "The widget scatter_drag generates a scatter plot that allows interaction through clicking and dragging the points on the graph.\n",
443
- "\n",
444
- "scatter_drag takes in two lists/arrays consisting of the x-coordinates and y-coordinates of the points to plot. It generates an interactive scatter plot where the points can be dragged by the user and a best fit line is updated automatically according to the placement of the points.\n",
445
- "\n",
446
- "scatter_drag does not allow response functions as inputs."
447
- ]
448
- },
449
- {
450
- "cell_type": "code",
451
- "execution_count": 10,
452
- "metadata": {},
453
- "outputs": [
454
- {
455
- "data": {
456
- "application/vnd.jupyter.widget-view+json": {
457
- "model_id": "40dc861f38114d0589514725ce5062e3",
458
- "version_major": 2,
459
- "version_minor": 0
460
- },
461
- "text/plain": [
462
- "VBox(children=(Label(value='y = 1.03x + 0.44'), Figure(animation_duration=250, axes=[Axis(scale=LinearScale(ma…"
463
- ]
464
- },
465
- "metadata": {},
466
- "output_type": "display_data"
467
- }
468
- ],
469
- "source": [
470
- "x_coords = np.arange(10)\n",
471
- "y_coords = np.arange(10) + np.random.rand(10)\n",
472
- "\n",
473
- "opts = {'xlim': (0, 9), 'ylim': (0, 11), 'animation_duration': 250}\n",
474
- "\n",
475
- "nbi.scatter_drag(x_coords, y_coords, options=opts)"
476
- ]
477
- },
478
- {
479
- "cell_type": "markdown",
480
- "metadata": {},
481
- "source": [
482
- "### `nbinteract.scatter`\n",
483
- "\n",
484
- "The scatter widgetr generates a scatter plot that allows interaction with the parameters to the response functions. This is different from scatter_drag which facilitates interaction using click and drag actions.\n",
485
- "\n",
486
- "The first two arguments of scatter are response functions that return the x and y-axis coordinates, respectively. Either argument can be arrays themselves. Arguments for the response functions must be passed in as keyword arguments to scatter in the format expected by interact. The response function for the y-coordinates will be called with the x-coordinates as its first argument."
487
- ]
488
- },
489
- {
490
- "cell_type": "code",
491
- "execution_count": 11,
492
- "metadata": {},
493
- "outputs": [
494
- {
495
- "data": {
496
- "application/vnd.jupyter.widget-view+json": {
497
- "model_id": "4bee645a8f074735b3a76d7611a7ec01",
498
- "version_major": 2,
499
- "version_minor": 0
500
- },
501
- "text/plain": [
502
- "VBox(children=(interactive(children=(IntSlider(value=105, description='n', max=200, min=10), Output()), _dom_c…"
503
- ]
504
- },
505
- "metadata": {},
506
- "output_type": "display_data"
507
- }
508
- ],
509
- "source": [
510
- "def x_values(n): return np.random.choice(100, n)\n",
511
- "def y_values(xs): return np.random.choice(100, len(xs))\n",
512
- "\n",
513
- "nbi.scatter(x_values, y_values, n=(10,200))"
514
- ]
515
- },
516
- {
517
- "cell_type": "markdown",
518
- "metadata": {},
519
- "source": [
520
- "### `nbinteract.line`\n",
521
- "\n",
522
- "The line widget generates a line plot that allows interaction with the parameters to the response functions.\n",
523
- "\n",
524
- "The first two arguments of line are response functions that return the x and y-axis coordinates, respectively. Either argument can be arrays themselves. Arguments for the response functions must be passed in as keyword arguments to line in the format expected by interact. The response function for the y-coordinates will be called with the x-coordinates as its first argument."
525
- ]
526
- },
527
- {
528
- "cell_type": "code",
529
- "execution_count": 12,
530
- "metadata": {},
531
- "outputs": [
532
- {
533
- "data": {
534
- "application/vnd.jupyter.widget-view+json": {
535
- "model_id": "e86bedcd6aa34fd99f7701ac7ea07efb",
536
- "version_major": 2,
537
- "version_minor": 0
538
- },
539
- "text/plain": [
540
- "VBox(children=(interactive(children=(IntSlider(value=30, description='max', max=50, min=10), IntSlider(value=5…"
541
- ]
542
- },
543
- "metadata": {},
544
- "output_type": "display_data"
545
- }
546
- ],
547
- "source": [
548
- "def x_values(max): return np.arange(0, max)\n",
549
- "def y_values(xs, sd):\n",
550
- " return xs + np.random.normal(0, scale=sd, size=len(xs))\n",
551
- "\n",
552
- "opts = {\n",
553
- " 'xlim': (0, 50),\n",
554
- " 'ylim': (0, 55),\n",
555
- " 'animation_duration': 250,\n",
556
- "}\n",
557
- "\n",
558
- "nbi.line(x_values, y_values, max=(10, 50), sd=(1, 10), options=opts)"
559
- ]
560
- },
561
- {
562
- "cell_type": "markdown",
563
- "metadata": {},
564
- "source": [
565
- "## Interactive Questions from nbinteract\n",
566
- "nbinteract also provides built-in methods to easily create multiple choice and short answer questions.\n"
567
- ]
568
- },
569
- {
570
- "cell_type": "markdown",
571
- "metadata": {},
572
- "source": [
573
- "### nbinteract.multiple_choice\n",
574
- "\n",
575
- "`nbinteract.multiple_choice` takes a question, a list of possible answer choices, and the correct answer. Clicking the buttons shows whether the choice was correct."
576
- ]
577
- },
578
- {
579
- "cell_type": "code",
580
- "execution_count": 13,
581
- "metadata": {},
582
- "outputs": [
583
- {
584
- "data": {
585
- "application/vnd.jupyter.widget-view+json": {
586
- "model_id": "d9f2357911f64e08bfd63b97e5f34b7b",
587
- "version_major": 2,
588
- "version_minor": 0
589
- },
590
- "text/plain": [
591
- "VBox(children=(HTML(value='<p style=\"line-height:18px;\">What is 10 + 2 * 5?</p>'), HBox(children=(Button(layou…"
592
- ]
593
- },
594
- "metadata": {},
595
- "output_type": "display_data"
596
- }
597
- ],
598
- "source": [
599
- "nbi.multiple_choice(question=\"What is 10 + 2 * 5?\",\n",
600
- " choices=['12', '60', '20'],\n",
601
- " answers=2)"
602
- ]
603
- },
604
- {
605
- "cell_type": "code",
606
- "execution_count": 14,
607
- "metadata": {
608
- "scrolled": true
609
- },
610
- "outputs": [
611
- {
612
- "data": {
613
- "application/vnd.jupyter.widget-view+json": {
614
- "model_id": "bb9674fe94b0491f83de231ff76bc149",
615
- "version_major": 2,
616
- "version_minor": 0
617
- },
618
- "text/plain": [
619
- "VBox(children=(HTML(value='<p style=\"line-height:18px;\">Select all prime numbers.</p>'), HBox(children=(Button…"
620
- ]
621
- },
622
- "metadata": {},
623
- "output_type": "display_data"
624
- }
625
- ],
626
- "source": [
627
- "nbi.multiple_choice(question=\"Select all prime numbers.\",\n",
628
- " choices=['12', '3', '31'],\n",
629
- " answers=[1, 2])"
630
- ]
631
- },
632
- {
633
- "cell_type": "markdown",
634
- "metadata": {},
635
- "source": [
636
- "### nbinteract.short_answer\n",
637
- "\n",
638
- "`nbinteract.short_answer` takes a question and an answer.\n",
639
- "\n",
640
- "The answer can either be a string, a list of strings, or a function that returns `True` when called with the user's input. If the function errors, an error message will be displayed."
641
- ]
642
- },
643
- {
644
- "cell_type": "code",
645
- "execution_count": 15,
646
- "metadata": {},
647
- "outputs": [
648
- {
649
- "data": {
650
- "application/vnd.jupyter.widget-view+json": {
651
- "model_id": "c488ca7374b0478bb5db7f877738df78",
652
- "version_major": 2,
653
- "version_minor": 0
654
- },
655
- "text/plain": [
656
- "VBox(children=(HTML(value='<p style=\"line-height:18px;\">What is 1+1?</p>'), HBox(children=(Text(value='', plac…"
657
- ]
658
- },
659
- "metadata": {},
660
- "output_type": "display_data"
661
- }
662
- ],
663
- "source": [
664
- "nbi.short_answer('What is 1+1?', answers='2', explanation='1+1 is 2')"
665
- ]
666
- },
667
- {
668
- "cell_type": "code",
669
- "execution_count": 16,
670
- "metadata": {},
671
- "outputs": [
672
- {
673
- "data": {
674
- "application/vnd.jupyter.widget-view+json": {
675
- "model_id": "8f9315d5c2fc4a9b9e1ca7c6e4433341",
676
- "version_major": 2,
677
- "version_minor": 0
678
- },
679
- "text/plain": [
680
- "VBox(children=(HTML(value='<p style=\"line-height:18px;\">Enter the first name of a member of the Beatles.</p>')…"
681
- ]
682
- },
683
- "metadata": {},
684
- "output_type": "display_data"
685
- }
686
- ],
687
- "source": [
688
- "nbi.short_answer('Enter the first name of a member of the Beatles.',\n",
689
- " ['John', 'Paul', 'George', 'Ringo'])"
690
- ]
691
- },
692
- {
693
- "cell_type": "code",
694
- "execution_count": 17,
695
- "metadata": {},
696
- "outputs": [
697
- {
698
- "data": {
699
- "application/vnd.jupyter.widget-view+json": {
700
- "model_id": "b0bbe10d65cc485294295b94e6fab3a6",
701
- "version_major": 2,
702
- "version_minor": 0
703
- },
704
- "text/plain": [
705
- "VBox(children=(HTML(value='<p style=\"line-height:18px;\">Enter an even number.</p>'), HBox(children=(Text(value…"
706
- ]
707
- },
708
- "metadata": {},
709
- "output_type": "display_data"
710
- }
711
- ],
712
- "source": [
713
- "nbi.short_answer('Enter an even number.', lambda x: int(x) % 2 == 0)"
714
- ]
715
- }
716
- ],
717
- "metadata": {
718
- "kernelspec": {
719
- "display_name": "Python 3",
720
- "language": "python",
721
- "name": "python3"
722
- },
723
- "language_info": {
724
- "codemirror_mode": {
725
- "name": "ipython",
726
- "version": 3
727
- },
728
- "file_extension": ".py",
729
- "mimetype": "text/x-python",
730
- "name": "python",
731
- "nbconvert_exporter": "python",
732
- "pygments_lexer": "ipython3",
733
- "version": "3.7.9"
734
- }
735
- },
736
- "nbformat": 4,
737
- "nbformat_minor": 4
738
- }