-
Notifications
You must be signed in to change notification settings - Fork 60
/
app.py
46 lines (33 loc) · 1.29 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from shiny import *
# ============================================================
# Counter module
# ============================================================
def counter_ui(label: str = "Increment counter") -> ui.TagChildArg:
return ui.div(
{"style": "border: 1px solid #ccc; border-radius: 5px; margin: 5px 0;"},
ui.h2("This is " + label),
ui.input_action_button(id="button", label=label),
ui.output_text_verbatim(id="out"),
)
def counter_server(input: Inputs, output: Outputs, session: Session):
count: reactive.Value[int] = reactive.Value(0)
@reactive.Effect()
@event(input.button)
def _():
count.set(count() + 1)
@output()
@render_text()
def out() -> str:
return f"Click count is {count()}"
counter_module = Module(counter_ui, counter_server)
# =============================================================================
# App that uses module
# =============================================================================
app_ui = ui.page_fluid(
counter_module.ui("counter1", "Counter 1"),
counter_module.ui("counter2", "Counter 2"),
)
def server(input: Inputs, output: Outputs, session: Session):
counter_module.server("counter1")
counter_module.server("counter2")
app = App(app_ui, server)