Introducing a new way to review your PRs.

Read the announcement

visgl / deck.gl

WebGL2 powered visualization framework

View on GitHub

23 documents · Updated Nov 20, 2026

docs / widgets-and-jupyter

Widgets and Jupyter

Deck.gl supports two ways to use a visualization without building a full JavaScript application shell. The standalone widget package adds DOM controls that live with a Deck instance, while the Jupyter widget bridge carries serialized deck.gl state and user events between a notebook kernel and the browser.

Integration boundary

The widget system sits between deck.gl's rendering and view state services and an outer host such as a plain web page, a notebook, or a Python binding. It gives that host a small UI and data channel without changing the role of the core renderer.

The two packages serve different host needs:

PackageMain roleHost contract
@deck.gl/widgetsProvide ready-made controls and view layout helpersA browser DOM element and a Deck instance
@deck.gl/jupyter-widgetConnect a notebook widget model to a browser Deck instanceJupyter widget model/view messages and serialized deck.gl JSON

The Jupyter bridge includes the widget package and the main deck.gl layer families in its browser bundle. It can also load extra browser libraries and make their exported classes available to notebook JSON. This lets notebook configuration name common or custom deck.gl objects without requiring a separate application bundle. See Application integrations for the wider set of host adapters.

Standalone widget package

@deck.gl/widgets is a browser UI layer for common map and data-view tasks. Each widget is attached to a Deck instance and can read or change view state, observe redraws, and receive picking events. The published package provides type declarations, ESM and CommonJS entry points, and a separate stylesheet entry, while deck.gl core and luma.gl remain host-managed peer runtimes.

Widget surface

The package covers the controls that users need to inspect and change a view. Controls can target one view or apply to the views that the Deck instance exposes.

Widget groupUser needRepresentative behavior
NavigationChange or restore the cameraZoom and reset-view controls update view state; the compass restores bearing and pitch
GeospatialRead or search spatial contextA compass reflects camera rotation; scale and geocoder controls support map reading and search
View controlChange the canvas arrangementFullscreen changes the host display; splitter controls let users resize view regions
InformationRead state at the point of interestInfo, popup, context-menu, scrollbar, and loading controls expose map or data state; a popup can anchor user content to a world position
LegendExplain color encodingThe color-scale control shows the color scales used by visible SQL layers, with categorical, interval, quantile, and continuous forms
Playback and choiceControl a data-driven experienceTimeline controls time and playback; selector and toggle controls report user choices
UtilitySupport the surrounding UIScreenshot and theme controls address capture and appearance; the statistics control exposes run-time metrics and device information

The package also exposes a layout model for rows, columns, overlays, spacers, and split regions. A layout turns a tree of deck.gl views into view bounds for the current canvas size, so a host can express multi-view composition without writing its own resize and split logic.

The experimental color-scale control adds a legend for color scales resolved from the layers currently visible in its target view. It can show categories, numeric intervals, quantile bins, or a sampled continuous ramp, and it keeps the legend readable with formatted boundaries and pointer or keyboard inspection.

References: modules/…/package.json• L24-35 modules/…/index.ts• L5-40 modules/…/index.ts• L66-92 modules/…/color-scale-widget.tsx• L165-293 modules/…/color-scale-widget.tsx• L295-430 modules/…/popup-widget.tsx• L12-70 modules/…/stats-widget.tsx• L31-79 modules/…/view-layout.ts• L7-16 modules/…/build-views-from-view-layout.ts• L119-172

Widget lifecycle

The core widget manager owns the relationship between controls and the Deck instance. It mounts each widget into a shared DOM area or a view-specific area, keeps the placement aligned with the view, and removes stale controls when declarative widget input changes.

The manager sends redraw and viewport information to widgets. It also routes hover, click, and drag input only to widgets that are global or attached to the event's view. A widget can therefore present UI beside a view while still using the Deck instance as the source of truth for camera and layer state.

Widgets use a small common contract: an identity, placement, optional view target, DOM rendering, and lifecycle hooks. The contract also permits a widget to use an outer container, which is useful when a host controls the page layout rather than the Deck canvas.

This diagram shows how host input and Deck state reach widget controls, then return as view changes or host callbacks.

flowchart LR
  A[Deck props or host code] --> B[Widget manager]
  B --> C[Widget DOM controls]
  B --> D[Viewport and redraw updates]
  E[Pointer or gesture event] --> B
  B --> C
  C --> F[View state or host callback]
  F --> A

References: modules/…/widget.ts• L15-35 modules/…/widget.ts• L75-103 modules/…/widget.ts• L146-184 modules/…/widget-manager.ts• L44-77 modules/…/widget-manager.ts• L100-129 modules/…/widget-manager.ts• L131-170

Widget state controls

Widgets that change the camera do so through Deck view state rather than through a second camera model. For example, the zoom control respects the active view's limits and can apply a transition, while the compass uses the current viewport to show orientation and reset it.

Widgets can use either local state or controlled state supplied by the host. Timeline and theme controls illustrate this boundary: a host may own the time, playback, or theme value and receive a callback, or the widget may manage that value itself. The stats widget follows the same pattern for its expanded display, while the popup widget reports open and closed changes and manages its own open state from its default value.

The stats widget can summarize Deck, luma, device, or custom metrics. It may refresh the display at a chosen redraw interval and format or reset selected values, so the host can balance run-time detail with update cost.

References: modules/…/zoom-widget.tsx• L105-175 modules/…/compass-widget.tsx• L102-139 modules/…/timeline-widget.tsx• L74-120 modules/…/timeline-widget.tsx• L206-235 modules/…/theme-widget.tsx• L96-118 modules/…/popup-widget.tsx• L56-115 modules/…/stats-widget.tsx• L94-120 modules/…/stats-widget.tsx• L176-217

Jupyter widget bridge

@deck.gl/jupyter-widget makes a Deck visualization a Jupyter DOM widget. The Python side owns a widget model, the browser side owns a widget view, and the bridge keeps serialized visualization state and interaction messages moving between them. Its published package also supplies the JupyterLab extension entry and treats the Jupyter widget base package as a shared singleton, so the notebook can connect its model and view through the host widget manager.

Notebook lifecycle

The browser view creates a transport for each widget instance. The transport creates a relative Deck container, builds the visualization from the model's initial state, applies later JSON or binary updates, and finalizes the Deck when the notebook widget is destroyed.

The bridge can run a standalone Deck or place deck.gl over a supported base map. With MapLibre, the base map owns the camera and deck.gl receives layer updates as an overlay. This keeps notebook view changes aligned with the map host instead of creating a second camera state.

The following flow shows the main notebook path from kernel state to browser rendering and back to Python callbacks.

sequenceDiagram
  participant P as Python or notebook kernel
  participant M as Jupyter widget model
  participant V as Browser widget view
  participant D as Deck instance
  P->>M: Set JSON and optional binary data
  M->>V: Sync model fields
  V->>D: Initialize or apply converted props
  D-->>V: Produce rendering and user events
  V-->>M: Send JSON event message
  M-->>P: Dispatch notebook callback
  P->>M: Send a later state update

JupyterLab discovers the bridge through its widget registry. The model and view use the same module name and version, so the notebook widget manager can match Python metadata with the browser code that implements it.

References: modules/…/jupyter-transport-view.js• L11-63 modules/…/playground.js• L15-69 modules/…/maplibre-utils.js• L12-87 modules/…/overlay-utils.js• L5-17 modules/…/plugin.js• L14-29 modules/…/version.js• L5-14 modules/…/package.json• L21-33 modules/…/package.json• L35-66

Serialized visualization state

The bridge treats notebook input as deck.gl JSON configuration. The browser converts that configuration into executable layers, views, widgets, effects, and provider integrations, then applies the result to the live Deck instance.

Large numeric data can travel through a binary buffer instead of being expanded into JSON. The model deserializes typed arrays, and the browser associates each layer's buffer with that layer before updating Deck. This path preserves the notebook-to-browser contract while reducing the cost of sending large point sets.

The bridge can also load custom browser libraries and merge their exported classes or functions into the JSON converter. ES module libraries can use an import map that points their deck.gl and luma.gl imports to the copies already used by the widget. This avoids conflicting runtime copies while extending the set of objects that notebook JSON can name.

Custom library loading does not block all rendering. The bridge can show the props that it can convert, retain the newest update that depends on an unloaded library, and retry that update after each requested library settles. If a library fails, the dependent layer or widget stays out of the converted props while unrelated content remains usable.

References: modules/…/jupyter-transport-model.js• L17-64 modules/…/playground.js• L49-81 modules/…/create-deck.js• L43-155 modules/…/create-deck.js• L157-239 modules/…/shared-modules.js• L7-75 modules/…/deserialize-matrix.js• L5-52 modules/…/package.json• L35-57

Interaction return path

The browser sends interaction results over the Jupyter widget back-channel. Click, hover, resize, view-state, and drag events become JSON messages, which the Python widget dispatches to registered handlers; click data also supports a selected-data result on the Python side.

The bridge supplies a default tooltip path for picked objects and also accepts text or HTML templates. It removes circular layer references before sending event data, so the notebook receives a data-shaped result rather than a live browser object graph. Background hover events without a picked object are not sent.

References: modules/…/jupyter-transport.js• L7-30 modules/…/create-deck.js• L242-315 modules/…/playground.js• L84-102 modules/…/widget-tooltip.js• L157-188 bindings/…/widget.py• L12-22 bindings/…/widget.py• L69-122

Python integration boundary

The JavaScript bridge defines the browser protocol, while pydeck defines the Python-facing widget model and callbacks. The current pydeck v0.9 code path does not enable the live Jupyter widget for show() or update(); show() renders an HTML iframe and update() reports that the Jupyter-specific path is not supported.

This means the bridge remains a protocol and browser integration boundary, but Python users must check the pydeck version and enabled path before relying on live kernel updates, binary transfer, or selection callbacks. For the Python construction layer and its CARTO boundary, see Python bindings.

References: bindings/…/jupyter.rst• L4-9 bindings/…/deck.py• L183-215 bindings/…/widget.py• L24-67

The widget packages complement, rather than replace, the other host adapters. React owns a Deck instance through component state, map integrations share a camera and canvas with a host map renderer, and Python bindings create serialized deck.gl configuration before a notebook or HTML host displays it.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the widget model and view module name and version aligned with the Python widget metadata and JupyterLab registry entry.
  • Keep JSON converter registration aligned with the classes and providers exported by the browser bundle, including any names that use a public alias for an underscored export.
  • Keep binary buffer layer identifiers aligned with the layer IDs used by the serialized JSON configuration.
  • Keep event message names aligned between browser dispatch and Python callback routing.
  • When changing widget placement or multi-view behavior, check both the shared widget root coordinates and the view-specific canvas offsets.
  • When changing custom ES module loading, keep the shared import-map specifiers aligned with the bundled deck.gl and luma.gl namespaces and install the map before a custom module resolves.
  • When changing a map overlay provider, keep camera ownership and layer-only update behavior aligned with the host map's event and view-state contract.
  • When changing the standalone package surface, keep its ESM, CommonJS, type, and stylesheet entry points aligned with the host's package resolution. Keep its deck.gl core and luma.gl peer runtime ranges compatible with the host.
  • When changing the Jupyter package bundle, keep its deck.gl, widget, map, and loader dependencies on the same release line as the bridge.
  • When changing controlled widget state, keep the state prop and its change callback aligned so the host applies the next value after user input.
  • When changing the color-scale widget, keep its public export and stylesheet selectors aligned with the legend's supported scale forms and target-view behavior.

Important failure modes

TriggerConsequenceGuard
The Jupyter model and browser module versions do not matchThe notebook widget manager cannot load the intended model or viewPublish and register the same module version on both sides
A serialized class is not in the converter or a custom library is not loadedA layer or widget stays out of the converted props and the view is incompleteRegister the class or wait for custom library loading before applying dependent props
A custom ES module resolves deck.gl or luma.gl to a second runtime copyThe library can fail at load or behave as if it uses a different runtimeUse the widget's shared module import map for supported bare specifiers
Binary data uses a layer ID that differs from the JSON layer IDThe wrong data is attached or the layer cannot receive its dataTreat layer IDs as the shared key across Python serialization and browser conversion
Python uses pydeck v0.9 live-widget methodsshow() falls back to an HTML iframe and update() raises NotImplementedErrorUse the supported HTML path or a pydeck version that enables the widget path
A MapLibre update includes only camera or general Deck propsThe overlay does not apply that state because the base map owns the cameraChange the MapLibre map through its host view-state path and send layer changes through Deck
A widget targets a missing view IDThe widget is hidden or receives no view-specific updatesUse a valid Deck view ID or leave the widget global
The host loads the widget package without its stylesheetControls can render without the intended layout and visual presentationLoad the package's published stylesheet entry with the widget bundle
A color-scale legend is used without the matching widget stylesThe legend can lose its layout, swatches, ramp, and interaction presentationLoad the standalone widget stylesheet together with the widget package
A layer does not expose a resolved color scaleThe color-scale legend has no entry for that layerConfigure a supported layer color scale and place the legend on the view that renders it
The host resolves incompatible core or luma.gl peer runtimesWidgets can fail at load or behave differently from the Deck instanceResolve compatible peer versions from the host application
The Jupyter bundle mixes deck.gl package versionsJSON conversion or provider integration can fail at run timeKeep bridge dependencies on the same deck.gl release line
A host supplies a controlled stats expansion value but does not apply the change callbackThe stats panel does not reflect the user's expand or collapse actionUpdate the controlled expanded value from onExpandedChange

Key files

FileWhy to read it
modules/…/package.jsonPublished package entry points, stylesheet export, and peer runtime contract
modules/…/index.tsPublic surface of the standalone widget package
modules/…/color-scale-widget.tsxExperimental legend for layer color scales and visible data ranges
modules/…/stylesheet.cssShared visual rules for built-in controls and the color-scale legend
modules/…/widget.tsShared widget contract and Deck-facing lifecycle
modules/…/widget-manager.tsMounting, placement, redraw, and event routing
modules/…/popup-widget.tsxWorld-anchored popup behavior and open-state callbacks
modules/…/stats-widget.tsxRuntime metric display and controlled expansion behavior
modules/…/view-layout.tsHigh-level model for nested multi-view layouts
modules/…/build-views-from-view-layout.tsConversion from authored layout to concrete Deck views
modules/…/package.jsonBrowser bundle dependencies and JupyterLab extension contract
modules/…/jupyter-transport-model.jsJupyter model fields and binary data boundary
modules/…/jupyter-transport-view.jsBrowser-side model synchronization and widget lifecycle
modules/…/playground.jsTransport callbacks and notebook-to-Deck update flow
modules/…/create-deck.jsJSON conversion, custom library loading, bundle registration, and host map selection
modules/…/shared-modules.jsShared runtime imports for custom ES module libraries
modules/…/maplibre-utils.jsMapLibre host map and deck.gl overlay boundary
modules/…/overlay-utils.jsLayer-only updates for overlays whose host owns the camera
bindings/…/widget.pyPython widget fields and event callback boundary
bindings/…/deck.pyCurrent pydeck display and update behavior