Skip to content

Commit 039bd49

Browse files
committed
Add apps with modules + global
1 parent c284dd5 commit 039bd49

File tree

13 files changed

+517
-0
lines changed

13 files changed

+517
-0
lines changed

shiny/playwright/controller/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ._input_buttons import (
22
InputActionButton,
33
InputActionLink,
4+
InputBookmarkButton,
45
InputDarkMode,
56
InputFile,
67
InputTaskButton,
@@ -77,6 +78,7 @@
7778
__all__ = [
7879
"InputActionButton",
7980
"InputActionLink",
81+
"InputBookmarkButton",
8082
"InputCheckbox",
8183
"InputCheckboxGroup",
8284
"InputDarkMode",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from shiny.express import app_opts, input, module, render, session, ui
2+
3+
app_opts(bookmark_store="url")
4+
5+
with ui.card():
6+
ui.card_header("Bookmarking Checkbox Demo")
7+
8+
# Non-modular section
9+
ui.h3("Non-Module Section")
10+
11+
# Basic checkbox with default value (False)
12+
ui.input_checkbox(id="basic", label="Basic checkbox")
13+
14+
@render.text
15+
def basic_text():
16+
return f"Checkbox value: {input.basic()}"
17+
18+
# module section
19+
20+
@module
21+
def checkbox_module(input, output, session):
22+
ui.h3("Checkbox Module")
23+
24+
# Basic checkbox with default value (True)
25+
ui.input_checkbox(id="module_checkbox", label="Basic module checkbox")
26+
27+
@render.text
28+
def checkbox_text():
29+
return f"Checkbox value: {input.module_checkbox()}"
30+
31+
checkbox_module("first")
32+
33+
ui.input_bookmark_button(id="bookmark_button", label="Bookmark this page")
34+
35+
36+
@session.bookmark.on_bookmarked
37+
async def _(url: str):
38+
await session.bookmark.update_query_string(url)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from playwright.sync_api import Page
2+
3+
from shiny.playwright import controller
4+
from shiny.pytest import create_app_fixture
5+
from shiny.run import ShinyAppProc
6+
7+
app = create_app_fixture(["app-express.py"])
8+
9+
10+
def test_checkbox_demo(page: Page, app: ShinyAppProc) -> None:
11+
page.goto(app.url)
12+
13+
# Test basic checkbox
14+
basic_checkbox = controller.InputCheckbox(page, "basic")
15+
basic_checkbox.expect_label("Basic checkbox")
16+
basic_checkbox.expect_checked(False)
17+
18+
basic_text = controller.OutputText(page, "basic_text")
19+
basic_text.expect_value("Checkbox value: False")
20+
21+
# Test module checkbox
22+
module_checkbox = controller.InputCheckbox(page, "first-module_checkbox")
23+
module_checkbox.expect_label("Basic module checkbox")
24+
module_checkbox.expect_checked(False)
25+
26+
module_text = controller.OutputText(page, "first-checkbox_text")
27+
module_text.expect_value("Checkbox value: False")
28+
29+
basic_checkbox.set(True)
30+
basic_checkbox.expect_checked(True)
31+
basic_text.expect_value("Checkbox value: True")
32+
module_checkbox.set(True)
33+
module_checkbox.expect_checked(True)
34+
module_text.expect_value("Checkbox value: True")
35+
36+
# Test bookmark button
37+
bookmark_button = controller.InputActionButton(page, "bookmark_button")
38+
bookmark_button.click()
39+
40+
# reload the page to test bookmark
41+
page.reload()
42+
43+
# Check if the basic checkbox is checked
44+
basic_checkbox.expect_checked(True)
45+
basic_text.expect_value("Checkbox value: True")
46+
# Check if the module checkbox is checked
47+
module_checkbox.expect_checked(True)
48+
module_text.expect_value("Checkbox value: True")
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from shiny.express import app_opts, input, module, render, session, ui
2+
3+
app_opts(bookmark_store="url")
4+
5+
with ui.card():
6+
ui.card_header("Bookmarking Checkbox Group Demo")
7+
8+
# Non-modular section
9+
ui.h3("Non-Module Section")
10+
11+
# Basic checkbox group with choices
12+
ui.input_checkbox_group(
13+
id="basic",
14+
label="Basic checkbox group",
15+
choices=["Option 1", "Option 2", "Option 3"],
16+
)
17+
18+
@render.text
19+
def basic_text():
20+
return f"Checkbox group values: {input.basic()}"
21+
22+
# module section
23+
24+
@module
25+
def checkbox_module(input, output, session):
26+
ui.h3("Checkbox Group Module")
27+
28+
# Module checkbox group with choices
29+
ui.input_checkbox_group(
30+
id="module_checkbox",
31+
label="Module checkbox group",
32+
choices=["Choice A", "Choice B", "Choice C"],
33+
)
34+
35+
@render.text
36+
def checkbox_text():
37+
return f"Checkbox group values: {input.module_checkbox()}"
38+
39+
checkbox_module("first")
40+
41+
ui.input_bookmark_button(id="bookmark_button", label="Bookmark this page")
42+
43+
44+
@session.bookmark.on_bookmarked
45+
async def _(url: str):
46+
await session.bookmark.update_query_string(url)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from shiny.express import app_opts, input, module, render, session, ui
2+
3+
app_opts(bookmark_store="url")
4+
5+
with ui.card():
6+
ui.card_header("Bookmarking Dark Mode Demo")
7+
8+
# Non-modular section
9+
ui.h3("Non-Module Section")
10+
11+
# Basic dark mode toggle
12+
ui.input_dark_mode(id="basic", label="Basic dark mode toggle")
13+
14+
@render.text
15+
def basic_text():
16+
return f"Dark mode value: {input.basic()}"
17+
18+
# module section
19+
20+
@module
21+
def dark_mode_module(input, output, session):
22+
ui.h3("Dark Mode Module")
23+
24+
# Module dark mode toggle
25+
ui.input_dark_mode(id="module_dark_mode", label="Module dark mode toggle")
26+
27+
@render.text
28+
def dark_mode_text():
29+
return f"Dark mode value: {input.module_dark_mode()}"
30+
31+
dark_mode_module("first")
32+
33+
ui.input_bookmark_button(id="bookmark_button", label="Bookmark this page")
34+
35+
36+
@session.bookmark.on_bookmarked
37+
async def _(url: str):
38+
await session.bookmark.update_query_string(url)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from shiny.express import app_opts, input, module, render, session, ui
2+
3+
app_opts(bookmark_store="url")
4+
5+
with ui.card():
6+
ui.card_header("Bookmarking Date Input Demo")
7+
8+
# Non-modular section
9+
ui.h3("Non-Module Section")
10+
11+
# Basic date input
12+
ui.input_date(
13+
id="basic",
14+
label="Basic date input",
15+
)
16+
17+
@render.text
18+
def basic_text():
19+
return f"Date value: {input.basic()}"
20+
21+
# module section
22+
23+
@module
24+
def date_module(input, output, session):
25+
ui.h3("Date Input Module")
26+
27+
# Module date input
28+
ui.input_date(
29+
id="module_date",
30+
label="Module date input",
31+
)
32+
33+
@render.text
34+
def date_text():
35+
return f"Date value: {input.module_date()}"
36+
37+
date_module("first")
38+
39+
ui.input_bookmark_button(id="bookmark_button", label="Bookmark this page")
40+
41+
42+
@session.bookmark.on_bookmarked
43+
async def _(url: str):
44+
await session.bookmark.update_query_string(url)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from shiny.express import app_opts, input, module, render, session, ui
2+
3+
app_opts(bookmark_store="url")
4+
5+
with ui.card():
6+
ui.card_header("Bookmarking Date Range Demo")
7+
8+
# Non-modular section
9+
ui.h3("Non-Module Section")
10+
11+
# Basic date range with default values
12+
ui.input_date_range(
13+
id="basic", label="Basic date range", start="2023-01-01", end="2023-12-31"
14+
)
15+
16+
@render.text
17+
def basic_text():
18+
return f"Date range values: {input.basic()}"
19+
20+
# module section
21+
22+
@module
23+
def date_module(input, output, session):
24+
ui.h3("Date Range Module")
25+
26+
# Module date range
27+
ui.input_date_range(
28+
id="module_date_range",
29+
label="Module date range",
30+
start="2023-06-01",
31+
end="2023-06-30",
32+
)
33+
34+
@render.text
35+
def date_text():
36+
return f"Date range values: {input.module_date_range()}"
37+
38+
date_module("first")
39+
40+
ui.input_bookmark_button(id="bookmark_button", label="Bookmark this page")
41+
42+
43+
@session.bookmark.on_bookmarked
44+
async def _(url: str):
45+
await session.bookmark.update_query_string(url)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from shiny.express import app_opts, input, module, render, session, ui
2+
3+
app_opts(bookmark_store="url")
4+
5+
with ui.card():
6+
ui.card_header("Bookmarking Radio Buttons Demo")
7+
8+
# Non-modular section
9+
ui.h3("Non-Module Section")
10+
11+
# Basic radio buttons with choices
12+
ui.input_radio_buttons(
13+
id="basic",
14+
label="Basic radio buttons",
15+
choices=["Option 1", "Option 2", "Option 3"],
16+
)
17+
18+
@render.text
19+
def basic_text():
20+
return f"Radio button value: {input.basic()}"
21+
22+
# module section
23+
24+
@module
25+
def radio_module(input, output, session):
26+
ui.h3("Radio Buttons Module")
27+
28+
# Module radio buttons with choices
29+
ui.input_radio_buttons(
30+
id="module_radio",
31+
label="Module radio buttons",
32+
choices=["Choice A", "Choice B", "Choice C"],
33+
)
34+
35+
@render.text
36+
def radio_text():
37+
return f"Radio button value: {input.module_radio()}"
38+
39+
radio_module("first")
40+
41+
ui.input_bookmark_button(id="bookmark_button", label="Bookmark this page")
42+
43+
44+
@session.bookmark.on_bookmarked
45+
async def _(url: str):
46+
await session.bookmark.update_query_string(url)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from shiny.express import app_opts, input, module, render, session, ui
2+
3+
app_opts(bookmark_store="url")
4+
5+
with ui.card():
6+
ui.card_header("Bookmarking Select Demo")
7+
8+
# Non-modular section
9+
ui.h3("Non-Module Section")
10+
11+
# Basic select with choices
12+
ui.input_select(
13+
id="basic",
14+
label="Basic select",
15+
choices={"option1": "Option 1", "option2": "Option 2", "option3": "Option 3"},
16+
)
17+
18+
@render.text
19+
def basic_text():
20+
return f"Select value: {input.basic()}"
21+
22+
# module section
23+
24+
@module
25+
def select_module(input, output, session):
26+
ui.h3("Select Module")
27+
28+
# Module select with choices
29+
ui.input_select(
30+
id="module_select",
31+
label="Module select",
32+
choices={
33+
"choiceA": "Choice A",
34+
"choiceB": "Choice B",
35+
"choiceC": "Choice C",
36+
},
37+
)
38+
39+
@render.text
40+
def select_text():
41+
return f"Select value: {input.module_select()}"
42+
43+
select_module("first")
44+
45+
ui.input_bookmark_button(id="bookmark_button", label="Bookmark this page")
46+
47+
48+
@session.bookmark.on_bookmarked
49+
async def _(url: str):
50+
await session.bookmark.update_query_string(url)

0 commit comments

Comments
 (0)