Skip to content

Commit 1232b67

Browse files
Copilotkarangattu
andcommitted
Fix insert_accordion_panel to work with express ui.accordion_panel
Co-authored-by: karangattu <[email protected]>
1 parent eaf5074 commit 1232b67

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

shiny/ui/_accordion.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Literal, Optional, TypeVar
3+
from typing import TYPE_CHECKING, Literal, Optional, TypeVar, Union
44

55
from htmltools import Tag, TagAttrs, TagAttrValue, TagChild, css, tags
66

@@ -16,6 +16,7 @@
1616

1717
if TYPE_CHECKING:
1818
from ..session import Session
19+
from ..express._recall_context import RecallContextManager
1920

2021
__all__ = (
2122
"accordion",
@@ -447,7 +448,7 @@ def update_accordion(
447448
@add_example()
448449
def insert_accordion_panel(
449450
id: str,
450-
panel: AccordionPanel,
451+
panel: Union[AccordionPanel, "RecallContextManager[AccordionPanel]"],
451452
target: Optional[str] = None,
452453
position: Literal["after", "before"] = "after",
453454
session: Optional[Session] = None,
@@ -486,14 +487,24 @@ def insert_accordion_panel(
486487
if position not in ("after", "before"):
487488
raise ValueError("`position` must be either 'after' or 'before'")
488489
session = require_active_session(session)
490+
491+
# Handle both AccordionPanel and RecallContextManager[AccordionPanel]
492+
from ..express._recall_context import RecallContextManager
493+
if isinstance(panel, RecallContextManager):
494+
# This is a RecallContextManager, extract the AccordionPanel
495+
accordion_panel = panel.fn(*panel.args, **panel.kwargs)
496+
else:
497+
# This is already an AccordionPanel
498+
accordion_panel = panel
499+
489500
# Add accordion ID to panel; Used when `accordion(multiple=False)`
490-
panel._accordion_id = id
501+
accordion_panel._accordion_id = id
491502

492503
_send_panel_message(
493504
id,
494505
session,
495506
method="insert",
496-
panel=session._process_ui(panel.resolve()),
507+
panel=session._process_ui(accordion_panel.resolve()),
497508
target=None if target is None else _assert_str(target),
498509
position=position,
499510
)

0 commit comments

Comments
 (0)