Skip to content

Commit

Permalink
Modify moduleapp example to be dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Jun 25, 2022
1 parent d8735fd commit a5397ae
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions examples/moduleapp/app.py
Expand Up @@ -30,18 +30,48 @@ def out() -> str:
return f"Click count is {count()}"


# ============================================================
# Counter Wrapper module -- shows that counter still works
# the same way when wrapped in a dynamic UI
# ============================================================
@module.ui
def counter_wrapper_ui() -> ui.TagChildArg:
return ui.output_ui("dynamic_counter")


@module.server
def counter_wrapper_server(
input: Inputs, output: Outputs, session: Session, label: str = "Increment counter"
):
@output()
@render.ui()
def dynamic_counter():
return counter_ui("counter", label)

counter_server("counter")


# =============================================================================
# App that uses module
# =============================================================================
app_ui = ui.page_fluid(
counter_ui("counter1", "Counter 1"),
counter_ui("counter2", "Counter 2"),
counter_wrapper_ui("counter2_wrapper"),
ui.output_ui("counter3_ui"),
)


def server(input: Inputs, output: Outputs, session: Session):
counter_server("counter1")
counter_server("counter2")
counter_wrapper_server("counter2_wrapper", "Counter 2")

@output()
@render.ui()
def counter3_ui():
counter_server("counter3")
return counter_ui("counter3", "Counter 3")

counter_server("counter")


app = App(app_ui, server)

0 comments on commit a5397ae

Please sign in to comment.