render_pydeck

render_pydeck class

Deprecated: use pydeck layers with render_maplibre instead.

Usage Source

render_pydeck(
    _fn: Optional[ValueFn[ValueT]] = None,
    *,
    width: Optional[str] = None,
    height: Optional[str] = None,
    fill: Optional[bool] = None,
    fillable: Optional[bool] = None,
    rate_policy: Optional[RatePolicy] = None,
    rate_delay: Optional[float] = None,
)

pydeck v0.9 removed its Jupyter widget (Deck.show() now returns static HTML and Deck.update() raises), so no ipywidgets bridge, shinywidgets included, can render a live pydeck.Deck. With pydeck v0.9 or newer, this decorator raises a TypeError explaining the alternatives below. (pydeck v0.8’s widget requires ipywidgets < 8, while shinywidgets requires ipywidgets >= 8.1.)

Alternatives:

  • Reactive maps from pydeck layers: pass pydeck.Layer objects to a maplibre map’s add_deck_layers() and render it with render_maplibre (requires pip install 'shinywidgets[maplibre]'). Restyle the rendered map in place with .widget.set_deck_layers() (the camera stays where the user left it), and read its state (e.g., "view_state", "clicked") with reactive_read().
  • Large data: lonboard and render_lonboard send binary data once and restyle layers without re-sending it.
  • Static maps: use shiny’s @render.ui and return deck.show() (a 500px-tall iframe), or, to fill the container, ui.tags.iframe(srcdoc=deck.to_html(as_string=True), style="border:0;width:100%;height:100%;flex:1 1 auto"). Every change re-sends the whole page and resets the camera, and there are no events back to Python. (Don’t return deck.to_html(): without a filename, it returns None.)

Parameters

width : Optional[str] = None

A CSS length unit (e.g., "400px" or "100%") for the output’s width.

height : Optional[str] = None

A CSS length unit for the output’s height. When None (the default), the output is designed to fill the height of its parent container (see fill and fillable).

fill : Optional[bool] = None

Whether the output should grow or shrink to fit its parent container. When None (the default), this is True if height is not specified.

fillable : Optional[bool] = None

Whether the output container should fill available space (scrolling its contents on overflow). When None (the default), this is True if height is not specified.

Examples

import pydeck as pdk
from maplibre import Map, MapOptions
from maplibre.basemaps import Carto
from shiny import reactive
from shiny.express import input, ui
from shinywidgets import render_maplibre

ui.input_slider("radius", "Hexagon radius (m)", 1000, 10000, 4000, step=500)

POINTS = [[-0.13, 51.51], [-0.12, 51.50], [-2.24, 53.48]]  # [lng, lat]


@render_maplibre
def deck():
    m = Map(MapOptions(style=Carto.DARK_MATTER, center=(-1.9, 52.25), zoom=6))
    # Filled (and restyled in place, without re-rendering the map) below
    m.add_deck_layers([])
    return m


@reactive.effect
def _():
    deck.widget.set_deck_layers([layer()])


def layer():
    return pdk.Layer(
        "HexagonLayer",
        POINTS,
        id="hex",
        get_position="-",
        radius=input.radius(),
        extruded=True,
    )