express.ui.input_bookmark_button

express.ui.input_bookmark_button(
    label='Bookmark...',
    *,
    icon=MISSING,
    width=None,
    disabled=False,
    id=BOOKMARK_ID,
    title="Bookmark this application's state and get a URL for sharing.",
    **kwargs,
)

Button for bookmarking/sharing.

A bookmark button is an input_action_button with a default label that consists of a link icon and the text "Bookmark...". It is meant to be used for bookmarking state.

Parameters

label : TagChild = 'Bookmark…'

The button label.

icon : TagChild | MISSING_TYPE = MISSING

The icon to display on the button.

width : Optional[str] = None

The CSS width, e.g. ‘400px’, or ‘100%’.

disabled : bool = False

Whether the button is disabled.

id : str = BOOKMARK_ID

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.

title : str = "Bookmark this application's state and get a URL for sharing."

A tooltip that is shown when the mouse cursor hovers over the button.

kwargs : TagAttrValue = {}

Additional attributes for the button.

Returns

: Tag

A UI element.

Multiple (module) buttons

By default, Shiny will listen for the default id being used and call session.bookmark() on button click. However, this will not work if the bookmark button is used within a module or more than one bookmark button is being utilized.

For both situations, a custom id value is required.

There are two recommendations to maintain the expected bookmark behavior: * The supplied id value should be excluded from bookmarking with session.bookmark.exclude.append(ID). * A reactive effect should be added that performs the bookmarking (session.bookmark()) when the button is pressed.

session.bookmark.exclude.append("CUSTOM_ID")

@reactive.effect
@reactive.event(input.CUSTOM_ID)
async def _():
    await session.bookmark()

See Also

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
from shiny.express import app_opts, session, ui

app_opts(bookmark_store="url")


ui.markdown(
    "Directions: "
    "\n1. Change the radio button selection below"
    "\n2. Save the bookmark."
    "\n3. Then, refresh your browser page to see the radio button selection has been restored."
)


ui.input_radio_buttons("letter", "Choose a letter", choices=["A", "B", "C"])
ui.input_bookmark_button()


@session.bookmark.on_bookmarked
async def _(url: str):
    await session.bookmark.update_query_string(url)