Skip to content

Commit a02ef62

Browse files
committed
pydeck's Deck()'s initialization method creates a reference to a model instance, so use tthat
This way, the deck instance can be registered/rendered more directly and be .update()d properly
1 parent 02b0650 commit a02ef62

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

examples/pydeck/app.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pydeck as pdk
2+
3+
from shiny import *
4+
from shinywidgets import *
5+
6+
app_ui = ui.page_fluid(
7+
ui.input_slider("zoom", "Zoom", 0, 20, 6, step=1),
8+
output_widget("pydeck")
9+
)
10+
11+
def server(input: Inputs, output: Outputs, session: Session):
12+
13+
UK_ACCIDENTS_DATA = "https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv"
14+
15+
layer = pdk.Layer(
16+
"HexagonLayer", # `type` positional argument is here
17+
UK_ACCIDENTS_DATA,
18+
get_position=["lng", "lat"],
19+
auto_highlight=True,
20+
elevation_scale=50,
21+
pickable=True,
22+
elevation_range=[0, 3000],
23+
extruded=True,
24+
coverage=1,
25+
)
26+
27+
view_state = pdk.ViewState(
28+
longitude=-1.415,
29+
latitude=52.2323,
30+
zoom=6,
31+
min_zoom=5,
32+
max_zoom=15,
33+
pitch=40.5,
34+
bearing=-27.36,
35+
)
36+
37+
deck = pdk.Deck(layers=[layer], initial_view_state=view_state)
38+
39+
# Register either the deck (or deck_widget) instance
40+
register_widget("pydeck", deck)
41+
42+
@reactive.Effect()
43+
def _():
44+
deck.initial_view_state.zoom = input.zoom()
45+
deck.update()
46+
47+
48+
app = App(app_ui, server)

shinywidgets/_shinywidgets.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ def _as_widget(x: object) -> Widget:
235235
try:
236236
from pydeck.widget import DeckGLWidget
237237

238-
x_ = x.to_json() # type: ignore
239-
x = DeckGLWidget()
240-
x.json_input = x_
238+
x = x.deck_widget
241239
except Exception as e:
242240
raise RuntimeError(f"Failed to coerce {x} into a DeckGLWidget: {e}")
243241

0 commit comments

Comments
 (0)