Ipywidgets

Widgets are an integral part of the Jupyter Dashboard. The following section explores Ipywidgets in greater detail. First, the widgets should be imported from the Ipywidgets library:

from ipywidgets import widgets

The following screenshot shows how a widget for text input is created:

Widget to get a text input

Now, let's print the value that was entered in the widget:

Figure 9.39: Widget to get a text input with printed output

Using similar methods, other widgets can be created. The following screenshot shows a Button widget:

Creating a Click button widget

Any widget has two parts: the UI and the event handler. The event handler is usually a Python script that instructs us about the response we should provide to the user input. In the preceding examples, the event handler printed a message based on the user's input.

Unlike the default widgets, interact is a special kind that chooses the form of the widget based on the user input. In the following screenshot, a single value was provided to the function by the widget. The interactive widget decided to create a slider input:

Creating a value slider widget

Now, let's change the input to Boolean, that is, True. The widget becomes a checkbox:

Creating a Boolean selector widget
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset