Custom Widgets and Tabs
You can create a new Widget and/or a new Tab.
Last updated
You can create a new Widget and/or a new Tab.
Last updated
You can add a new Widget, e.g. to visualize a metric that Evidently does not provide. You can also create a Tab by combining existing and custom widgets to get a new Dashboard and HTML report.
Example 1 (California Housing, PSI metric for Data Drift). Refer to it to reproduce and explore the implementation of a custom Widget and a Tab on your own:
Below is a step-by-step guide with a simplified example.
To create a new Widget, you should create a class derived from our base class: https://github.com/evidentlyai/evidently/blob/main/src/evidently/dashboard/widgets/widget.py
Then you need to modify the calculate method. It takes as arguments reference
data, current
data, and column_mapping
. Your Widget can use any information from these variables.
Here is an instruction on how to create a simple Widget with the information about the target distribution on reference and current data.
Example 2 (California Housing, Simple Widget and Tab):
We make a prototype of our Widget in Jupyter Notebook. Using Plotly, we create a graph that we want to see in the Dashboard.
2. Now we need to write a class for our Widget.
Create a new Python file. Copy the code from https://github.com/evidentlyai/evidently/blob/main/src/evidently/dashboard/widgets/reg_pred_and_actual_in_time_widget.py - we will use it as starting point and edit to create a custom implementation.
We start from imports. We change the Plotly import, remove analyzer import, and the default colors:
Then, we remove the arguments that we don’t need from the init
function. We remove the analyzers
function because we don't use its result in the custom Widget.
Next, we remove everything from the calculate method until the JSON and return section. We then paste the code for the custom plot we created earlier from the Jupyter notebook.
Tip: don't forget to replace the DataFrame names!
Finally, we fix the JSON conversion and return sections:
That’s it!
Now you can put this file from where you can import the module, and paste it into the Evidently tab like this:
Creating a custom Tab is even easier. You need to create a class derived from the base class: https://github.com/evidentlyai/evidently/blob/main/src/evidently/dashboard/tabs/base_tab.py
Again, let's take an existing Evidently tab as an example and change it.
Just import the custom widgets and list them in the attribute "widgets". You can specify the "verbose" parameter to have an option to adjust the tab composition.
To generate the report, run these commands: