Skip to content

Commit e252589

Browse files
authored
docs: Explicitly call out module usage in bookmark button (#1983)
1 parent c441a62 commit e252589

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Bug fixes
1919

20+
* Explicitly call out module usage in UI input bookmark button documentation. (#1983)
21+
2022
* Fix missing session when trying to display an error duing bookmarking. (#1984)
2123

2224

shiny/bookmark/_button.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def input_bookmark_button(
3939
disabled
4040
Whether the button is disabled.
4141
id
42-
An ID for the bookmark button. The only time it is necessary to set the ID unless you have more than one bookmark button in your application. If you specify an input ID, it should be excluded from bookmarking with `session.bookmark.exclude.append(ID)`, and you must create a reactive effect that performs the bookmarking (`session.bookmark()`) when the button is pressed.
42+
An ID for the bookmark button. This should only be provided when multiple buttons are needed (or used inside a module). See the note on multiple buttons.
4343
title
4444
A tooltip that is shown when the mouse cursor hovers over the button.
4545
kwargs
@@ -50,6 +50,30 @@ def input_bookmark_button(
5050
:
5151
A UI element.
5252
53+
Multiple (module) buttons
54+
-------------------------
55+
56+
By default, Shiny will listen for the default `id` being used and call
57+
`session.bookmark()` on button click. However, this will not work if the bookmark
58+
button is used within a module or more than one bookmark button is being utilized.
59+
60+
For both situations, a custom `id` value is required.
61+
62+
There are two recommendations to maintain the expected bookmark behavior:
63+
* The supplied `id` value should be excluded from bookmarking with
64+
`session.bookmark.exclude.append(ID)`.
65+
* A reactive effect should be added that performs the bookmarking
66+
(`session.bookmark()`) when the button is pressed.
67+
68+
```python
69+
session.bookmark.exclude.append("CUSTOM_ID")
70+
71+
@reactive.effect
72+
@reactive.event(input.CUSTOM_ID)
73+
async def _():
74+
await session.bookmark()
75+
```
76+
5377
See Also
5478
--------
5579
* :func:`~shiny.ui.input_action_button`

0 commit comments

Comments
 (0)