Hello I am new to dash-deck, and I am currently working on a project to interactively project 1M plus datapoints using plotly dash.
I managed to build the map using pydeck and incorporated it in a html.Div() as mentioned above in some of the discussion threads. However I am not able to efficiently use the callbacks, as in my call back I am returning a new json rendered map (asking to redraw the whole thing over again every time a filter to be changed). my current basic layout is having a hexagonlayer map with a slider to change the size of the hexagon.
here is a sample of the data I started with (basically some lng/lats)- original dataset has more than 10M points with extra features:
{0: [-73.88237, 40.767281],
1: [-73.8459137, 40.84584539999999],
2: [-74.03995549999999, 40.6280321],
3: [-73.9614156, 40.6711639],
4: [-73.8459137, 40.84584539999999],
5: [-73.9092079, 40.7422696],
6: [-73.7525064, 40.6808144],
7: [-73.96642369999999, 40.6024728],
8: [-118.2513821, 34.04436260000001],
9: [-73.8459137, 40.84584539999999],
10: [-73.8936568, 40.7124245],
11: [-73.86616889999999, 40.6728365],
12: [-73.724429, 40.73412099999999],
13: [-73.724429, 40.73412099999999],
14: [-73.88421869999999, 40.6615298],
15: [-73.8871125, 40.6589543],
16: [-73.7525064, 40.6808144],
17: [-73.7800216, 40.7139847],
18: [-73.99492, 40.621994],
19: [-74.03878379999999, 40.6150368],
20: [-73.920355, 40.6587468],
21: [-74.1645396, 40.6198977],
22: [-73.92049399999999, 40.6469995],
23: [-73.7390612, 40.7073529],
24: [-73.8847139, 40.8687028],
25: [-73.92049399999999, 40.6469995],
26: [-73.8459137, 40.84584539999999],
27: [-73.933052, 40.5948416],
28: [-73.79152169999999, 40.7688436],
29: [-73.84066, 40.880436],
30: [-73.7525064, 40.6808144],
31: [-73.9223354, 40.6216635],
32: [-73.9223354, 40.6216635],
33: [-73.9223354, 40.6216635],
34: [-73.9223354, 40.6216635],
35: [-73.9223354, 40.6216635],
36: [-73.9223354, 40.6216635],
37: [-73.9223354, 40.6216635],
38: [-73.9223354, 40.6216635],
39: [-73.9223354, 40.6216635],
40: [-73.88421869999999, 40.6615298],
41: [-73.994796, 40.6906308],
42: [-73.89217560000002, 40.7398612],
43: [-73.9930308, 40.7244612],
44: [-74.122231, 40.613041],
45: [-73.8655869, 40.7202579],
46: [-73.746861, 40.6975088],
47: [-73.8813086, 40.9532636],
48: [-73.7800216, 40.7139847],
49: [-73.9694054, 40.7577363]}
My initial call back code is below
@app.callback(
[Output('SliderHeader', 'children'), Output('deck-gl', 'children')],
Input('hexagonSizeSlider', 'value')
)
def hexagonSizeSlider(hexagonSizeSlider_value):
#creating a slider value to be visible on screen
slider_value= "Hexagon Size: {}".format(hexagonSizeSlider_value)
#creating the map layers
#creating the hexagon layer
hexagonlayer= pydeck.Layer(
"HexagonLayer",
final,
get_position= ['lon', 'lat'],
auto_highlight= True,
elevation_scale= 10,
pickable= True,
elevation_range= [0,50],
extruded= True,
coverage= 1
)
#creating a geojson layer for NYC
geojson_color= [3, 252, 211]
geojson= pydeck.Layer(
"GeoJsonLayer",
nyc_geo,
opacity= 0.05,
stroked= True,
filled= True,
extruded= False,
wireframe= True,
get_line_color= geojson_color,
get_fill_color= geojson_color
)
#set viewport location
view_state= pydeck.ViewState(
longitude= -73.935242,
latitude= 40.730610,
zoom=9,
min_zoom= 5,
max_zoom= 15,
pitch= 40.5,
bearing= 0)
#creating a tooltip
tooltip= {"html": '<b>Borough:</b> {Boro Code}',
'style': {'color' : 'white'}}
#render
r= pydeck.Deck(layers= [geojson, hexagonlayer],
initial_view_state= view_state,
# tooltip= True,
height= 700,
)
return slider_value, r
I then tried to use r.update() but not sure where should it fit in the callback, and had no luck in getting it work. I get errors and no maps appears
@app.callback(
Output('SliderHeader', 'children'),
Input('hexagonSizeSlider', 'value')
)
def hexagonSizeSlider(hexagonSizeSlider_value):
#creating a slider value to be visible on screen
slider_value= "Hexagon Size: {}".format(hexagonSizeSlider_value)
#create a deck.gl hexagonlayer
hexagonlayer.coverage= [float(hexagonSizeSlider_value)]
r.update()
return slider_value
I would also like to filter upon more features and have the the map adapt quickly, another small sample of a dataset with more features. For instance, only showing points for selected Borough, Vehicle Make or a date
Issue Date lat lon Vehicle Make Boro Code
0 2019-06-12 40.767281 -73.882370 CHEVR 4
1 2019-06-17 40.845845 -73.845914 HONDA 2
2 2019-06-17 40.628032 -74.039955 KIA 3
3 2019-06-17 40.671164 -73.961416 NISSA 3
4 2019-06-18 40.845845 -73.845914 SUBAR 2
I would appreciate your advice on how to optimize the data update without having to redraw the map every single time. and any tips on how to filter, aggregate on other features (Date, vehicle make, Borough Code).
Thanks in advance