Issue with ReactiveHTML components in panel == 1.5.5

Dear community,

I encountered an issue when working with ReactiveHTML components after upgrading to panel==1.5.5. Below is a small example that demonstrates the problem.

I have a single CheckBoxGroup widget with two options: “A” and “B.” In the example, “A” is selected by default. When I deselect it (leaving no options selected), Panel throws the following error:

AttributeError: ‘str’ object has no attribute ‘name’
mapping = {o.name: o for o in old}

It appears that at least one element must remain selected so there is an object with a .name attribute. This worked fine before upgrading to panel==1.5.5. In version 1.5.4, it would simply return an empty array, which was acceptable behavior.

I would greatly appreciate any guidance on how to resolve or work around this issue.

Thank you,

With best regards,

Sergey

import panel as pn
import param
from panel.reactive import ReactiveHTML

pn.extension()


class CustomComponent(ReactiveHTML):

    groups = param.ListSelector(
        default=["A"],
        objects=["A", "B"],
    )

    _scripts = {
        "groups": """console.log(data.groups)""",
    }


component = CustomComponent()
groupWidget = pn.widgets.CheckBoxGroup.from_param(
    component.param.groups,
    name="Group",
    value=["A"],
    options=["A", "B"],
    inline=True,
)

pn.Column(groupWidget, component).servable()

I’d recommend trying JSComponent; I think it works better JSComponent — Panel v1.5.5

Thank you @ahuang11! I am currently in a situation where it would be too large an undertaking to refactor everything into a JSCompoenent, and I’m wondering if there’s a simpler solution that would still allow me to use ReactiveHTML, which worked just fine before the Panel update.

Add a fix here: fix: Don't error if data does not have name attribute by hoxbro · Pull Request #7655 · holoviz/panel · GitHub

2 Likes

Thanks for pushing it forward!