-
Notifications
You must be signed in to change notification settings - Fork 60
/
app.py
60 lines (44 loc) · 1.67 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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, counter0: reactive.Calc_[int]
) -> int:
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()}"
@reactive.Effect()
def _():
print("Clicked global counter", counter0())
# print("Clicked global counter", inputs.counter0())
return 1
counter_module = Module(counter_ui, counter_server)
# =============================================================================
# App that uses module
# =============================================================================
app_ui = ui.page_fluid(
counter_module.ui("counter1", label="Counter 1"),
counter_module.ui("counter2", "Counter 2"),
ui.input_action_button("counter0", "Print global counter"),
)
def server(inputs: Inputs, output: Outputs, sess: Session):
@reactive.Calc()
def counter0():
return inputs.counter0()
counter_module.server("counter1", counter0=counter0)
counter_module.server("counter2", counter0=counter0)
app = App(app_ui, server)