|  | 
|  | 1 | +from shiny import App, Inputs, Outputs, Session, reactive, ui | 
|  | 2 | + | 
|  | 3 | +app_ui = ui.page_sidebar( | 
|  | 4 | +    ui.sidebar( | 
|  | 5 | +        ui.input_action_button("add", "Add 'Dynamic' tab"), | 
|  | 6 | +        ui.input_action_button("removeFoo", "Remove 'Foo' tabs"), | 
|  | 7 | +        ui.input_action_button("addFoo", "Add New 'Foo' tab"), | 
|  | 8 | +        ui.input_action_button("hideTab", "Hide 'Foo' tab"), | 
|  | 9 | +        ui.input_action_button("showTab", "Show 'Foo' tab"), | 
|  | 10 | +        ui.input_action_button("hideMenu", "Hide 'Static' nav_menu"), | 
|  | 11 | +        ui.input_action_button("showMenu", "Show 'Static' nav_menu"), | 
|  | 12 | +    ), | 
|  | 13 | +    ui.navset_tab( | 
|  | 14 | +        ui.nav_panel("Hello", "This is the hello tab"), | 
|  | 15 | +        ui.nav_panel("Foo", "This is the Foo tab", value="Foo"), | 
|  | 16 | +        ui.nav_menu( | 
|  | 17 | +            "Static", | 
|  | 18 | +            ui.nav_panel("Static 1", "Static 1", value="s1"), | 
|  | 19 | +            ui.nav_panel("Static 2", "Static 2", value="s2"), | 
|  | 20 | +            value="Menu", | 
|  | 21 | +        ), | 
|  | 22 | +        id="tabs", | 
|  | 23 | +    ), | 
|  | 24 | +) | 
|  | 25 | + | 
|  | 26 | + | 
|  | 27 | +def server(input: Inputs, output: Outputs, session: Session): | 
|  | 28 | +    @reactive.effect() | 
|  | 29 | +    @reactive.event(input.add) | 
|  | 30 | +    def _(): | 
|  | 31 | +        id = "Dynamic-" + str(input.add()) | 
|  | 32 | +        ui.nav_insert( | 
|  | 33 | +            "tabs", | 
|  | 34 | +            ui.nav_panel(id, id), | 
|  | 35 | +            target="s2", | 
|  | 36 | +            position="before", | 
|  | 37 | +        ) | 
|  | 38 | + | 
|  | 39 | +    @reactive.effect() | 
|  | 40 | +    @reactive.event(input.removeFoo) | 
|  | 41 | +    def _(): | 
|  | 42 | +        ui.nav_remove("tabs", target="Foo") | 
|  | 43 | + | 
|  | 44 | +    @reactive.effect() | 
|  | 45 | +    @reactive.event(input.addFoo) | 
|  | 46 | +    def _(): | 
|  | 47 | +        n = str(input.addFoo()) | 
|  | 48 | +        ui.nav_insert( | 
|  | 49 | +            "tabs", | 
|  | 50 | +            ui.nav_panel("Foo-" + n, "This is the new Foo-" + n + " tab", value="Foo"), | 
|  | 51 | +            target="Menu", | 
|  | 52 | +            position="before", | 
|  | 53 | +            select=True, | 
|  | 54 | +        ) | 
|  | 55 | + | 
|  | 56 | +    @reactive.effect() | 
|  | 57 | +    @reactive.event(input.hideTab) | 
|  | 58 | +    def _(): | 
|  | 59 | +        ui.nav_hide("tabs", target="Foo") | 
|  | 60 | + | 
|  | 61 | +    @reactive.effect() | 
|  | 62 | +    @reactive.event(input.showTab) | 
|  | 63 | +    def _(): | 
|  | 64 | +        ui.nav_show("tabs", target="Foo") | 
|  | 65 | + | 
|  | 66 | +    @reactive.effect() | 
|  | 67 | +    @reactive.event(input.hideMenu) | 
|  | 68 | +    def _(): | 
|  | 69 | +        ui.nav_hide("tabs", target="Menu") | 
|  | 70 | + | 
|  | 71 | +    @reactive.effect() | 
|  | 72 | +    @reactive.event(input.showMenu) | 
|  | 73 | +    def _(): | 
|  | 74 | +        ui.nav_show("tabs", target="Menu") | 
|  | 75 | + | 
|  | 76 | + | 
|  | 77 | +app = App(app_ui, server) | 
0 commit comments