-
Notifications
You must be signed in to change notification settings - Fork 100
[Bug]: Bookmarking with modules not working #1976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@schloerke thank you for taking a look. Just to clarify - the problem could be I did not set up bookmarks correct for using in modules. In that case adding some documentation about using bookmarks in modules would be helpful :) The other possible scenarios are:
|
I found it after a sleep. Which means the current approach is not working.
... Is the correct answer. This behavior is in both R Shiny and py-shiny. I'll update the docs and tag you as a reviewer. |
Awesome thank you :) |
For reference, here is an example that works with modules and bookmarks: from loguru import logger
from shiny import App, Inputs, Outputs, Session, module, ui, reactive
from starlette.requests import Request
# App UI **must** be a function to ensure that each user restores their own UI values.
def app_ui(request: Request):
return ui.page_fluid(
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.hr(),
inputs_ui("inputs_module"),
)
@module.ui
def inputs_ui():
return ui.TagList(
ui.input_radio_buttons("letter", "Choose a letter", choices=["A", "B", "C"]),
ui.input_bookmark_button(id="inputs_module_bookmark", label="Save bookmark!"),
)
@module.server
def inputs_server(input: Inputs, output: Outputs, session: Session):
session.bookmark.exclude.append("inputs_module_bookmark")
@reactive.effect
@reactive.event(input.inputs_module_bookmark)
async def _do_bookmark():
logger.debug("Bookmarking state...")
await session.bookmark()
@session.bookmark.on_bookmarked
async def _on_bookmark(url: str):
logger.debug("Updating URL...")
logger.debug(f"{url=}")
await session.bookmark.update_query_string(url)
updated_url = await session.bookmark.get_bookmark_url()
logger.debug(f"{updated_url=}")
await session.bookmark.show_bookmark_url_modal()
def server(input: Inputs, output: Outputs, session: Session):
inputs_server("inputs_module")
app = App(app_ui, server, bookmark_store="url") |
Component
Other
Severity
P0 - Critical (crash/unusable)
Shiny Version
1.4.0
Python Version
3.13.2
Minimal Reproducible Example
Behavior
bookmarks-dont-work.mp4
In contrast, when not using modules, it does work.
bookmark-works.mp4
Error Messages (if any)
Environment
The text was updated successfully, but these errors were encountered: