Skip to content

Commit

Permalink
Support h3 deck layers in shiny apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Jul 18, 2024
1 parent 5c671bd commit 3959490
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
17 changes: 15 additions & 2 deletions _experimental/h3_deck_layer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from maplibre import MapOptions
from maplibre import MapOptions, render_maplibregl
from maplibre.basemaps import Carto
from maplibre.controls import NavigationControl
from maplibre.ipywidget import MapWidget as Map
from maplibre.ui import use_deckgl, use_h3
from shiny.express import app, ui

m = Map(
MapOptions(
Expand All @@ -27,4 +29,15 @@
}

m.add_deck_layers([h3_hexagon_layer], tooltip="{{ hex }} count: {{ count }}")
m.save("/tmp/py-maplibre-express.html")

use_h3()
use_deckgl()


@render_maplibregl
def render_map():
return m


if __name__ == "__main__":
m.save("/tmp/py-maplibre-express.html", preview=True)
15 changes: 13 additions & 2 deletions maplibre/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def output_maplibregl(id_: str, height: [int | str] = 200) -> Tag:


DECKGL_VERSION = "9.0.16"
H3_VERSION = "4.1.0"

h3_dep = HTMLDependency(
name="h3",
version=H3_VERSION,
source={"href": f"https://unpkg.com/h3-js@{H3_VERSION}/dist/"},
script={"src": "h3-js.umd.js"},
)


def use_h3() -> Tag:
return ui.div(h3_dep)


deckgl_dep = HTMLDependency(
name="deckgl",
Expand All @@ -51,8 +64,6 @@ def output_maplibregl(id_: str, height: [int | str] = 200) -> Tag:
script={"src": "dist.min.js", "type": "module"},
)

# TODO: Remove duplicated constant
# DECKGL_VERSION = "9.0.16"

deckgl_json_dep = HTMLDependency(
name="deckgljson",
Expand Down

0 comments on commit 3959490

Please sign in to comment.