Skip to content

Commit 0fd3921

Browse files
committed
Add some examples (not finished)
1 parent 221dc0d commit 0fd3921

File tree

9 files changed

+114
-9
lines changed

9 files changed

+114
-9
lines changed

docs/_quartodoc-core.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ quartodoc:
104104
- ui.input_bookmark_button
105105
- bookmark.restore_input
106106
- bookmark.Bookmark
107-
- session.Session.bookmark.exclude
108107
- bookmark.BookmarkState
109108
- bookmark.RestoreState
110109
- kind: page
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from starlette.requests import Request
2+
3+
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
4+
5+
6+
# App UI **must** be a function to ensure that each user restores their own UI values.
7+
def app_ui(request: Request):
8+
return ui.page_fluid(
9+
ui.markdown(
10+
"Directions: "
11+
"\n1. Change the radio button selection below"
12+
"\n2. Save the bookmark."
13+
"\n3. Then, refresh your browser page to see the radio button selection has been restored."
14+
),
15+
ui.hr(),
16+
ui.input_radio_buttons("letter", "Choose a letter", choices=["A", "B", "C"]),
17+
ui.input_bookmark_button(label="Save bookmark!"),
18+
)
19+
20+
21+
def server(input: Inputs, output: Outputs, session: Session):
22+
23+
# @reactive.effect
24+
# @reactive.event(input.letter, ignore_init=True)
25+
# async def _():
26+
# await session.bookmark()
27+
28+
@session.bookmark.on_bookmarked
29+
async def _(url: str):
30+
await session.bookmark.update_query_string(url)
31+
32+
33+
app = App(app_ui, server, bookmark_store="url")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from starlette.requests import Request
2+
3+
from shiny import reactive, render
4+
from shiny.express import app_opts, input, session, ui
5+
6+
app_opts(bookmark_store="url")
7+
8+
9+
ui.markdown(
10+
"Directions: "
11+
"\n1. Change the radio button selection below"
12+
"\n2. Save the bookmark."
13+
"\n3. Then, refresh your browser page to see the radio button selection has been restored."
14+
)
15+
16+
17+
ui.input_radio_buttons("letter", "Choose a letter", choices=["A", "B", "C"])
18+
ui.input_bookmark_button()
19+
20+
21+
@session.bookmark.on_bookmarked
22+
async def _(url: str):
23+
await session.bookmark.update_query_string(url)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from htmltools import tags
2+
from starlette.requests import Request
3+
4+
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
5+
from shiny._namespaces import resolve_id
6+
7+
8+
def custom_input_text(
9+
id: str,
10+
value: str = "",
11+
) -> Tag:
12+
13+
resolved_id = resolve_id(id)
14+
return tags.div(
15+
"Custom input text:",
16+
tags.input(
17+
id=resolve_id(id),
18+
type="text",
19+
value=value,
20+
placeholder="Type here...",
21+
),
22+
class_="shiny-input-container",
23+
style=css(width=width),
24+
)
25+
26+
27+
# App UI **must** be a function to ensure that each user restores their own UI values.
28+
def app_ui(request: Request):
29+
return ui.page_fluid(
30+
custom_input_text("myid", value="Default value - Hello, world!"),
31+
ui.input_bookmark_button(),
32+
# ui.markdown(
33+
# "Directions: "
34+
# "\n1. Change the radio button selection below"
35+
# "\n2. Save the bookmark."
36+
# "\n3. Then, refresh your browser page to see the radio button selection has been restored."
37+
# ),
38+
# ui.hr(),
39+
# ui.input_radio_buttons("letter", "Choose a letter", choices=["A", "B", "C"]),
40+
# ui.input_bookmark_button(label="Save bookmark!"),
41+
)
42+
43+
44+
def server(input: Inputs, output: Outputs, session: Session):
45+
46+
@session.bookmark.on_bookmarked
47+
async def _(url: str):
48+
await session.bookmark.update_query_string(url)
49+
50+
51+
app = App(app_ui, server, bookmark_store="url")

shiny/bookmark/_button.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
from htmltools import HTML, Tag, TagAttrValue, TagChild
44

5+
from .._docstring import add_example
56
from .._namespaces import resolve_id
67
from ..types import MISSING, MISSING_TYPE
78
from ..ui._input_action_button import input_action_button
89

910
BOOKMARK_ID = "._bookmark_"
1011

1112

13+
@add_example()
1214
def input_bookmark_button(
1315
label: TagChild = "Bookmark...",
1416
*,

shiny/playwright/controller/_navs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from playwright.sync_api import expect as playwright_expect
77
from typing_extensions import Literal
88

9-
from shiny.types import ListOrTuple
10-
9+
from ...types import ListOrTuple
1110
from .._types import PatternOrStr, Timeout
1211
from ..expect import expect_to_have_class, expect_to_have_style
1312
from ..expect._internal import expect_attribute_to_have_value

shiny/playwright/controller/_output.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from playwright.sync_api import Locator, Page
77
from playwright.sync_api import expect as playwright_expect
88

9-
from shiny.render._data_frame import ColumnFilter, ColumnSort
10-
9+
from ...render._data_frame import ColumnFilter, ColumnSort
1110
from .._types import AttrValue, ListPatternOrStr, PatternOrStr, StyleValue, Timeout
1211
from ..expect import expect_not_to_have_class, expect_to_have_class
1312
from ..expect._internal import (

shiny/session/_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@
6464
from ._utils import RenderedDeps, read_thunk_opt, session_context
6565

6666
if TYPE_CHECKING:
67-
from shiny.bookmark._serializers import Unserializable
68-
6967
from .._app import App
7068
from ..bookmark import Bookmark
69+
from ..bookmark._serializers import Unserializable
7170

7271

7372
class ConnectionState(enum.Enum):
@@ -1457,6 +1456,7 @@ async def _serialize(
14571456
# TODO: Barret - Q: Should this be ignoring any Input key that starts with a "."?
14581457
if key.startswith(".clientdata_"):
14591458
continue
1459+
# Ignore all bookmark inputs
14601460
if key == BOOKMARK_ID or key.endswith(
14611461
f"{ResolvedId._sep}{BOOKMARK_ID}"
14621462
):

shiny/ui/_input_task_button.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
from htmltools import HTML, Tag, TagAttrValue, TagChild, css, tags
99

10-
from shiny.types import MISSING, MISSING_TYPE
11-
1210
from .._docstring import add_example
1311
from .._namespaces import resolve_id
1412
from .._typing_extensions import ParamSpec
1513
from ..reactive._extended_task import ExtendedTask
1614
from ..reactive._reactives import effect
15+
from ..types import MISSING, MISSING_TYPE
1716
from ._html_deps_py_shiny import spin_dependency
1817
from ._html_deps_shinyverse import components_dependencies
1918

0 commit comments

Comments
 (0)