From a5397ae5cf308620de6f541761ba53077ca274b1 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Fri, 24 Jun 2022 20:49:29 -0700 Subject: [PATCH] Modify moduleapp example to be dynamic --- examples/moduleapp/app.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/examples/moduleapp/app.py b/examples/moduleapp/app.py index f6e83b995..66519889c 100644 --- a/examples/moduleapp/app.py +++ b/examples/moduleapp/app.py @@ -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)