Skip to content

Commit 53e0bfe

Browse files
committed
Updating express test
1 parent 4818091 commit 53e0bfe

File tree

5 files changed

+113
-98
lines changed

5 files changed

+113
-98
lines changed

shiny/api-examples/insert_nav_panel/app-core.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ui.input_action_button("add", "Add 'Dynamic' tab"),
66
ui.input_action_button("removeFoo", "Remove 'Foo' tabs"),
77
ui.input_action_button("addFoo", "Add New 'Foo' tab"),
8+
ui.input_action_button("addTextPanel", "Add Text Panel"),
89
),
910
ui.navset_tab(
1011
ui.nav_panel("Hello", "This is the hello tab"),
@@ -32,6 +33,17 @@ def _():
3233
position="before",
3334
)
3435

36+
@reactive.effect()
37+
@reactive.event(input.addTextPanel)
38+
def _():
39+
id = "Text-" + str(input.addTextPanel())
40+
ui.insert_nav_panel(
41+
"tabs",
42+
id,
43+
target="s2",
44+
position="before",
45+
)
46+
3547
@reactive.effect()
3648
@reactive.event(input.removeFoo)
3749
def _():
@@ -49,5 +61,17 @@ def _():
4961
select=True,
5062
)
5163

64+
@reactive.effect()
65+
@reactive.event(input.addTextPanel)
66+
def _():
67+
n = str(input.addFoo())
68+
ui.insert_nav_panel(
69+
"tabs",
70+
"Placeholder Text Panel",
71+
target="Menu",
72+
position="before",
73+
select=True,
74+
)
75+
5276

5377
app = App(app_ui, server)

shiny/api-examples/insert_nav_panel/app-express.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
ui.input_action_button("add", "Add 'Dynamic' tab")
66
ui.input_action_button("removeFoo", "Remove 'Foo' tabs")
77
ui.input_action_button("addFoo", "Add New 'Foo' tab")
8+
ui.input_action_button("addTextPanel", "Add Text Panel"),
9+
810

911
with ui.navset_tab(id="tabs"):
1012
with ui.nav_panel("Hello", value="Hello"):
@@ -31,6 +33,13 @@ def _():
3133
ui.remove_nav_panel("tabs", target="Foo")
3234

3335

36+
@reactive.effect()
37+
@reactive.event(input.add)
38+
def _():
39+
id = "Dynamic-" + str(input.add())
40+
ui.insert_nav_panel("tabs", title=id, value=id, target="s2", position="before")
41+
42+
3443
@reactive.effect()
3544
@reactive.event(input.addFoo)
3645
def _():
Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
from shiny import reactive
2-
from shiny.express import render
3-
from .modules import custom_sidebar, add_to_counter_content
4-
5-
tabs_added = reactive.value(0)
6-
7-
8-
def increment_tabs_counter():
9-
tabs_added.set(tabs_added() + 1)
10-
11-
12-
custom_sidebar(
13-
"nav",
14-
_on_click=increment_tabs_counter,
15-
label="Dynamic Sidebar",
16-
)
17-
18-
19-
add_to_counter_content(
20-
"buttonAdder",
21-
_on_click=increment_tabs_counter,
22-
starting_value=0,
23-
label="Add to Counter",
24-
)
25-
26-
27-
@render.code
28-
def out():
29-
return f"Tabs added: {tabs_added()}"
2+
from shiny.express import ui, module
3+
4+
5+
@module
6+
def my_nav(input, output, session):
7+
with ui.navset_card_tab(id="navset"):
8+
with ui.nav_panel("Panel 1"):
9+
"This is the first panel"
10+
ui.input_action_button("hideTab", "Hide panel 2")
11+
ui.input_action_button("showTab", "Show panel 2")
12+
ui.input_action_button("deleteTabs", "Delete panel 2")
13+
14+
@reactive.effect
15+
def _():
16+
ui.insert_nav_panel(
17+
"navset",
18+
"Panel 2",
19+
"This is the second panel",
20+
)
21+
22+
@reactive.effect()
23+
@reactive.event(input.showTab)
24+
def _():
25+
ui.show_nav_panel("navset", target="Panel 2")
26+
27+
@reactive.effect()
28+
@reactive.event(input.hideTab)
29+
def _():
30+
ui.hide_nav_panel("navset", target="Panel 2")
31+
32+
@reactive.effect()
33+
@reactive.event(input.deleteTabs)
34+
def _():
35+
ui.remove_nav_panel("navset", "Panel 2")
36+
37+
38+
my_nav("foo")
39+
my_nav("bar")

tests/playwright/shiny/components/express_navs/modules.py

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
from playwright.sync_api import Page, expect
3+
4+
from shiny.playwright import controller
5+
from shiny.run import ShinyAppProc
6+
7+
8+
@pytest.mark.flaky(reruns=3, reruns_delay=2)
9+
def test_dynamic_navs(page: Page, local_app: ShinyAppProc) -> None:
10+
page.goto(local_app.url)
11+
12+
# Page begins with 2 tabs: "Hello" and "Foo" and a nav menu with 2 static items.
13+
controller.NavsetTab(page, "foo-navset").expect_nav_titles(["Panel 1", "Panel 2"])
14+
controller.NavsetTab(page, "bar-navset").expect_nav_titles(["Panel 1", "Panel 2"])
15+
16+
# Click hide-tab to hide the Foo tabs
17+
hidetab = controller.InputActionButton(page, "foo-hideTab")
18+
hidetab.click()
19+
20+
# Expect the Foo tabs to be hidden
21+
navpanel = controller.NavPanel(page, "foo-navset", "Panel 2").loc
22+
expect(navpanel).to_be_hidden()
23+
24+
# Expect the bar tabs to not be affected
25+
navpanel2 = controller.NavPanel(page, "bar-navset", "Panel 2").loc
26+
expect(navpanel2).to_be_visible()
27+
28+
# Click show-tab to show the Foo tabs again
29+
showtab = controller.InputActionButton(page, "foo-showTab")
30+
showtab.click()
31+
32+
# Expect the Foo tabs to be visible again
33+
navpanel2 = controller.NavPanel(page, "foo-navset", "Panel 2").loc
34+
expect(navpanel2).to_be_visible()
35+
navpanel3 = controller.NavPanel(page, "bar-navset", "Panel 2").loc
36+
expect(navpanel3).to_be_visible()
37+
38+
# Click the remove button to remove the panel 2 in bar
39+
removeTab = controller.InputActionButton(page, "bar-deleteTabs")
40+
removeTab.click()
41+
controller.NavsetTab(page, "bar-navset").expect_nav_titles(["Panel 1"])
42+
controller.NavsetTab(page, "foo-navset").expect_nav_titles(["Panel 1", "Panel 2"])

0 commit comments

Comments
 (0)