Skip to content

fix: Introduce a more ergonomic API for express.ui.insert_accordion_panel() #2042

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jul 24, 2025

Closes #1802
Supersedes #2031

Minimal example of new API:

from shiny import reactive
from shiny.express import ui

with ui.accordion(id="acc"):
    with ui.accordion_panel("Panel 1"):
        "This is the first panel."


@reactive.effect
def _():
    ui.insert_accordion_panel("acc", "Panel 2", "This is the second panel.")

Whereas, with the old API:

from shiny import reactive
from shiny.express import ui

with ui.accordion(id="acc"):
    with ui.accordion_panel("Panel 1"):
        "This is the first panel."

@reactive.effect
def _():
    with @ui.hold() as panel:
        ui.accordion_panel("Panel 2"):
            "This is the second panel."
    ui.insert_accordion_panel("acc", panel)

@cpsievert
Copy link
Collaborator Author

@karangattu thanks for kick-starting this effort! Would you mind finishing this PR off (i.e., updating tests, examples, and docs to use the new API)?

@karangattu karangattu self-assigned this Jul 24, 2025
@cpsievert cpsievert added this to the Next Release milestone Jul 24, 2025
Introduces a new app and Playwright test to verify dynamic updating and insertion of accordion panels in Shiny Express UI. Tests cover initial panel rendering, updating panel content and title, and adding new panels via action buttons.
Replaces the previous list-based accordion panel creation with context-managed blocks for improved readability and structure. Updates dynamic panel insertion to match the new format, specifying both the section title and narrative.
@karangattu
Copy link
Collaborator

karangattu commented Jul 25, 2025

@karangattu thanks for kick-starting this effort! Would you mind finishing this PR off (i.e., updating tests, examples, and docs to use the new API)?

I added a test along with modifications to the example app. Where do you want me to make changes in the docs? @cpsievert

@cpsievert
Copy link
Collaborator Author

Where do you want me to make changes in the docs?

I mainly had the api-examples in mind, but also just wanted to make sure we check each usage of insert_accordion_panel(). From a quick look, it looks like we're good on docs, but we could also update tests/playwright/shiny/components/accordion/app.py to use the more modern API.

@cpsievert cpsievert force-pushed the fix/insert-accordion-panel branch from 3b571b5 to 47ccb7c Compare July 25, 2025 19:59
@cpsievert cpsievert marked this pull request as ready for review July 25, 2025 19:59
@karangattu
Copy link
Collaborator

tests/playwright/shiny/components/accordion/app.py

just to clarify the new api for insert_accordion_panel is only for express apps or Core apps should be able to use this api as well?

# core app
def accordion_panel(
    title: TagChild,
    *args: TagChild | TagAttrs,
    value: str | MISSING_TYPE | None = MISSING,
    icon: TagChild = None,
    **kwargs: TagAttrValue
) -> AccordionPanel
# express app
def insert_accordion_panel(
    id: str,
    panel_title: str,
    *panel_contents: TagChild | TagAttrs,
    panel_value: str | MISSING_TYPE | None = MISSING,
    panel_icon: TagChild = None,
    target: str | None = None,
    position: Literal['after', 'before'] = "after",
    session: Session | None = None
) -> None

@cpsievert
Copy link
Collaborator Author

Yep, Express and Core API for insert_accordion_panel() will be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shiny.express.ui.accordion_panel() doesn’t work with insert_accordion_panel() , but shiny.ui.accordion_panel() does
2 participants