PerspectiveWidget
tutorial¶PerspectiveWidget
is a Jupyterlab plugin that allows you to visualize and transform data using the full capabilities of Perspective and perspective-viewer
, all within a notebook.
from datetime import date, datetime
data = {
"int": [i for i in range(4)],
"float": [i * 1.25 for i in range(4)],
"str": ["a", "b", "c", "d"],
"bool": [True, False, True, False],
"date": [date.today() for i in range(4)],
"datetime": [datetime.now() for i in range(4)]
}
PerspectiveWidget
¶To create an instance of the widget, initialize PerspectiveWidget
with a perspective.Table
, a dataset, a schema, or None
.
import random
import string
from perspective import Table, PerspectiveWidget
widget = PerspectiveWidget(data, plugin="y_line", row_pivots=["str"], columns=["int", "float"])
widget
Once the widget has been created, you can call load()
and update()
on the widget instance, and the widget will reflect the new dataset.
When load()
is called multiple times, the widget compares the column names of the new dataset with the column names of the old dataset.
Because attempting to pivot/sort/filter etc. on a column not in the dataset raises an error, the Widget will clear its configuration state if the columns are found to be different.
PerspectiveWidget.update()
¶Updating the widget with new data is easy - simply call update()
on the instance with new data.
widget.update({
"int": [i for i in range(4, 9)],
"float": [i * 1.25 for i in range(4, 9)],
"str": [random.choice(string.ascii_letters) for i in range(4, 9)],
"bool": [True, False, True, False],
"date": [date.today() for i in range(4, 9)],
"datetime": [datetime.now() for i in range(4, 9)]
}) # rendered widget will automatically show new data