Skip to content
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

ReactiveHTML: TypeError: Object of type Button is not JSON serializable #2743

Closed
MarcSkovMadsen opened this issue Sep 17, 2021 · 5 comments · Fixed by #2780
Closed

ReactiveHTML: TypeError: Object of type Button is not JSON serializable #2743

MarcSkovMadsen opened this issue Sep 17, 2021 · 5 comments · Fixed by #2780
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Sep 17, 2021

I'm on Panel 0.12.1 and trying to create a floating panel using jsPanel and ReactiveHTML https://discourse.holoviz.org/t/how-do-i-use-jspanel-with-panel-and-reactivehtml/2819.

While experimenting I get the error

  File "C:\Users\masma\Anaconda3\envs\aw-lib\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "C:\Users\masma\Anaconda3\envs\aw-lib\lib\site-packages\bokeh\core\json_encoder.py", line 261, in default
    return self.transform_python_types(obj)
  File "C:\Users\masma\Anaconda3\envs\aw-lib\lib\site-packages\bokeh\core\json_encoder.py", line 228, in transform_python_types
    return super().default(obj)
  File "C:\Users\masma\Anaconda3\envs\aw-lib\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Button is not JSON serializable

from

import panel as pn
import param

pn.extension()


class JsPanel(pn.reactive.ReactiveHTML):
    object = param.Parameter()

    _template = """
<div id="element">My content</div>
"""
JsPanel(object=pn.widgets.Button(name="My Widget")).servable()

I believe there are use cases where the reactiveHTML class would like to hold Panel widgets.

@MarcSkovMadsen MarcSkovMadsen added the type: bug Something isn't correct or isn't working label Sep 17, 2021
@MarcSkovMadsen MarcSkovMadsen added this to the 0.13.0 milestone Sep 17, 2021
@arifin-chemist89
Copy link

As user cases that Marc have shown here, reactiveHTML could be potentially to be used as a wrapper for panel objects to improve its applicability. Really hope this could be implemented soon.

@philippjfr
Copy link
Member

This is supported, the error message just sucks, you have to actually insert the object into the template though:

import panel as pn
import param

class JsPanel(pn.reactive.ReactiveHTML):
    object = param.Parameter()

    _template = """
<div id="element">${object}</div>
"""

JsPanel(object=pn.widgets.Button(name="My Widget"))

@MarcSkovMadsen
Copy link
Collaborator Author

My use case is to NOT insert it into the ReactiveHTML _template. That seems not be supported then?

@philippjfr
Copy link
Member

Oh, I think you can do that by setting a negative precedence on the parameter.

@philippjfr
Copy link
Member

Okay let's discuss some behaviors that we could consider here. I think the best solution here is to check whether a parameter is referenced in the template or in a script and if it isn't we simply do not sync it. This will require some additional parsing of the scripts but overall seems fairly straightforward and most sensible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants