AltairWidget API#
Bases: AnyWidget
Flicker-free Altair chart widget.
Wraps an Altair chart and uses the Vega View API to update data in-place when only the data portion of the spec changes, avoiding full DOM rebuilds.
The widget should be created once and then updated via the chart setter
from a reactive cell. This keeps the DOM element stable and allows the
JavaScript side to detect data-only changes and apply them smoothly.
Examples:
import altair as alt
import pandas as pd
from wigglystuff import AltairWidget
df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
chart = alt.Chart(df).mark_point().encode(x="x", y="y")
widget = AltairWidget(chart)
widget
Create an AltairWidget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chart
|
Any
|
An Altair chart object or a Vega-Lite spec dict. If |
None
|
width
|
int
|
Container width in pixels. |
600
|
height
|
int
|
Container height in pixels. |
400
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in wigglystuff/altair_widget.py
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
spec |
dict |
Full Vega-Lite spec (from chart.to_dict()). |
width |
int |
Container width in pixels. |
height |
int |
Container height in pixels. |