Skip to content

Commit 06584f8

Browse files
committed
Add shiny example using modules
1 parent 5434985 commit 06584f8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/shiny/app_with_modules.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from shiny import App, ui, module, reactive
2+
from maplibre import output_maplibregl, render_maplibregl, Map, MapContext
3+
4+
5+
@module.ui
6+
def shiny_module_ui():
7+
return ui.page_fluid(
8+
ui.panel_title("MapLibre"),
9+
ui.input_action_button("btn", "Click"),
10+
output_maplibregl("mapgl", height=600),
11+
)
12+
13+
14+
@module.server
15+
def shiny_module_server(input, output, session):
16+
17+
@render_maplibregl
18+
def mapgl():
19+
m = Map()
20+
return m
21+
22+
@reactive.effect
23+
@reactive.event(input.btn)
24+
async def move_it():
25+
async with MapContext("mapgl") as m:
26+
m.add_call("flyTo", {"center": [-1.66928, 48.1024159], "zoom": 15})
27+
28+
29+
app_ui = ui.page_fluid(shiny_module_ui("shiny_mod"))
30+
31+
32+
def server(input, output, session):
33+
shiny_module_server("shiny_mod")
34+
35+
36+
app = App(app_ui, server)
37+

0 commit comments

Comments
 (0)