Hi.
In this video we will learn how to make our notebooks interactive with IPI
widget.
Jupyter Widgets are interactive browser controls for Jupyter notebooks,
like basic form controls like sliders, check boxes,
text inputs, patterns, combo boxes, and others.
It can be container controls like taps, accordions,
horizontal or vertical layout boxes and so on.
And also advanced controls like maps two D or three D
visualizations, data grids and others.
There are core and custom jupyter widgets and you can explore them more from the
provided links in the references section.
Now we will create a section where we will plot in the same scatter plot like we
all already did in our notebook.
So the scatter plot with two variables from our dataset,
but we'll have the option to select X and the Y variable from our Jupyter
widget,
specifically with a combo box and the option to fit the regression with a simple
checkbox.
Let's import our classes first. We
will need the combo box,
horizontal box checkbox and interactive output.
Let's create a new section called IPI widget.
And now I will paste here the code
and let's explain it.
Here we create our widgets.
The first two are the combo boxes to filter x, and the y variable
value is the first value, uh, which is shown when the widget launches
placeholder. This is a text when the combo box is empty.
These are the options for us to select from.
This is the text, uh, which is shown next to the widget.
And if Azure option is true, then in order to execute the code,
some value must be selected.
It is basically the same for the other combo box. And, um,
let's explain the plot regression function
here, recreate our chart,
and here we are fitting the regression model based on the value of the checkbox.
We align our controls horizontally,
and then we connect our plotting function with the widgets
and we display the output. Let's run it.
We see that our chart is nicely plotted. Uh, widgets are visible.
Let's change one variable,
and you see that the plot is automatically refreshed.
Let's try this one.
And the regression, this is working as well.
Unfortunately, when we export this file,
this functionality is not preserved, uh,
because the plotting requires running python kernel because we execute Python
code, but we can save widget state,
and this is plotted in the exported file. Let's see, how does it look like?
Go to widgets, save notebook, widget, state,
save the notebook, and let's export this to H T M L.
We see here the plot, also the widgets,
but when we change the values, nothing will happen.
As you can see, Jupyter gets with the widgets.
Very powerful when you start exploring them. Uh,
start with the method to interact, uh, which is, uh, very easy to use as well.
In our next video, we will turn our notebook into a dashboard with voa.