Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions panel/io/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ def param_to_jslink(model, widget):
from ..widgets import LiteralInput, Widget

param_pane = widget._param_pane

# If param_pane is a class (not an instance), it means the widget was created
# via Widget.from_param() as a class method. In this case, we cannot access
# instance attributes like _widgets, so we skip JS link conversion.
if isinstance(param_pane, type):
return

pobj = param_pane.object
pname = [k for k, v in param_pane._widgets.items() if v is widget]
watchers = [
Expand Down
48 changes: 48 additions & 0 deletions panel/tests/io/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,51 @@ def test_embed_widget_disabled(document, comm):
with config.set(embed=True):
model = panel.get_root(document, comm)
assert embed_state(panel, model, document) is None



def test_embed_widget_from_param_class(document, comm):
"""Test that widgets created via from_param on class parameters can be embedded."""
import param

from panel.widgets import RadioButtonGroup

class Test(param.Parameterized):
fn = param.Selector(default="sin", objects=["sin", "cos"])

# Create widget from class parameter
widget = RadioButtonGroup.from_param(Test.param.fn)
panel = Row(widget)

# Should not raise AttributeError when embedding
with config.set(embed=True):
model = panel.get_root(document, comm)

# embed_state should succeed (returns None when no state to embed)
result = embed_state(panel, model, document)
# Since this widget was created via class method, param_to_jslink should
# return early and not create any jslinks
assert result is None

def test_embed_widget_from_param_instance(document, comm):
"""Test that widgets created via from_param on instance parameters can be embedded."""
import param

from panel.widgets import RadioButtonGroup

class Test(param.Parameterized):
fn = param.Selector(default="sin", objects=["sin", "cos"])

# Create widget from instance parameter
test = Test()
widget = RadioButtonGroup.from_param(test.param.fn)
panel = Row(widget)

# Should not raise AttributeError when embedding
with config.set(embed=True):
model = panel.get_root(document, comm)

# embed_state should succeed without raising AttributeError
# Returns None when there are no widgets with state to embed
result = embed_state(panel, model, document)
assert result is None # No embeddable state for simple widgets without links
Loading