|Each interactive element presented on this page uses time-consuming operations that take a while to finish. The elements are built through a backend in the cloud. Please be patient to see the results.|
Many libraries are available for Jupyter (IPython) to choose from. One of the most commonly used libraries for widgets is IPyWidgets and the visualizations (plots) of Matplotlib, BQplot or GGplot.
In addition to the popular widgets, the NBI module offers additional GUI elements via the integrated interact-core library, which are useable in a very simple way.
Find with that page a commonly used set of widgets for interactive textbooks. Some more options are available for interactivity, but this selection shows the most used. Interactive widgets are provided natively by Jupyter Notebooks using the library
ipywidgets. Find common examples in the textbooks below.
Widgets from ipywidgets
The library ipywidgets, also known as jupyter-widgets, are interactive HTML widgets for Jupyter notebooks and the IPython kernel. Notebooks come alive when interactive widgets are used. Users gain control of their data and can visualize changes in the data.
Widgets from nbinteract
|The current version of j1-nbinteract 1.x is limited to Notebook v6 (Classic Notebook). The latest version Jupyter Notebook v7 (JupyterLab) are supported by upcoming versions of j1-nbinteract 2.x.|
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.
nbinteract.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.
nbinteract.bar generates an bar plot that allows interaction with the parameters for the response functions.
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.
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.
Interactive Scatter chart
nbinteract.scatter_drag generates a scatter plot that allows interaction through clicking and dragging the points on the graph.
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.
| The widget |
nbinteract.scatter 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.
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.
nbinteract.line widget generates a line plot that allows interaction with the parameters to the response functions. 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.
To enable educators to create and share interactive web pages for learning, beside widgets for plotting interactive widgets for asking questions are available as well.
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.
nbinteract.short_answer takes a question and an answer. 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.