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

type of LiteralInput does not work with pn.Param #1574

Closed
MarcSkovMadsen opened this issue Sep 11, 2020 · 1 comment · Fixed by #1614
Closed

type of LiteralInput does not work with pn.Param #1574

MarcSkovMadsen opened this issue Sep 11, 2020 · 1 comment · Fixed by #1614
Labels
type: bug Something isn't correct or isn't working

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Sep 11, 2020

I would like to use a LiteralInput as the widget in pn.Param of a Parameterized class but it is not possible.

As type provides the type of widget in the below pn.Param example the type of a LIteralInput cannot be provided.

import param
import panel as pn
pn.extension()

WIDGETS = {
    "a_literal": {
        "type": pn.widgets.LiteralInput, "sizing_mode": "fixed", "width": 400, "placeholder": "Input a dictionary!"
    }
}

class ParameterizedApp(param.Parameterized):
    a_literal = param.Dict(default=None, label="A Dictionary")
    view = param.Parameter()
    
    
    def __init__(self, **params):
        super().__init__(**params)
        
        self.view = pn.Param(self, parameters=["a_literal"], widgets=WIDGETS)
        
parameterized_app = ParameterizedApp()
parameterized_app.view

So I can input a list even though the parameter is a dict.

image

@MarcSkovMadsen MarcSkovMadsen added the TRIAGE Default label for untriaged issues label Sep 11, 2020
@MarcSkovMadsen
Copy link
Collaborator Author

and ... this is of course not possible

import param
import panel as pn
pn.extension()

WIDGETS = {
    "a_literal": {
        "type": pn.widgets.LiteralInput, "sizing_mode": "fixed", "width": 400, "placeholder": "Input a dictionary!", "type": dict
    }
}

class ParameterizedApp(param.Parameterized):
    a_literal = param.Dict(default=None, label="A Dictionary")
    view = param.Parameter()
    
    
    def __init__(self, **params):
        super().__init__(**params)
        
        self.view = pn.Param(self, parameters=["a_literal"], widgets=WIDGETS)
        
parameterized_app = ParameterizedApp()
parameterized_app.view
----------------------------------------------------------------
AttributeError                 Traceback (most recent call last)
<ipython-input-5-bbb4723617e4> in <module>
     19         self.view = pn.Param(self, parameters=["a_literal"], widgets=WIDGETS)
     20 
---> 21 parameterized_app = ParameterizedApp()
     22 parameterized_app.view

<ipython-input-5-bbb4723617e4> in __init__(self, **params)
     17         super().__init__(**params)
     18 
---> 19         self.view = pn.Param(self, parameters=["a_literal"], widgets=WIDGETS)
     20 
     21 parameterized_app = ParameterizedApp()

c:\repos\private\panel-extensions-template\.venv\lib\site-packages\panel\param.py in __init__(self, object, **params)
    182             'object', 'parameters', 'name', 'display_threshold', 'expand_button',
    183             'expand', 'expand_layout', 'widgets', 'show_labels', 'show_name'])
--> 184         self._update_widgets()
    185 
    186     def __repr__(self, depth=0):

c:\repos\private\panel-extensions-template\.venv\lib\site-packages\panel\param.py in _update_widgets(self, *events)
    240             self._widgets = {}
    241         else:
--> 242             self._widgets = self._get_widgets()
    243 
    244         alias = {'_title': 'name'}

c:\repos\private\panel-extensions-template\.venv\lib\site-packages\panel\param.py in _get_widgets(self)
    502         else:
    503             widgets = []
--> 504         widgets += [(pname, self.widget(pname)) for pname in self._ordered_params]
    505         return OrderedDict(widgets)
    506 

c:\repos\private\panel-extensions-template\.venv\lib\site-packages\panel\param.py in <listcomp>(.0)
    502         else:
    503             widgets = []
--> 504         widgets += [(pname, self.widget(pname)) for pname in self._ordered_params]
    505         return OrderedDict(widgets)
    506 

c:\repos\private\panel-extensions-template\.venv\lib\site-packages\panel\param.py in widget(self, p_name)
    370                 kw['step'] = p_obj.step
    371 
--> 372         kwargs = {k: v for k, v in kw.items() if k in widget_class.param}
    373 
    374         if isinstance(widget_class, Widget):

c:\repos\private\panel-extensions-template\.venv\lib\site-packages\panel\param.py in <dictcomp>(.0)
    370                 kw['step'] = p_obj.step
    371 
--> 372         kwargs = {k: v for k, v in kw.items() if k in widget_class.param}
    373 
    374         if isinstance(widget_class, Widget):

AttributeError: type object 'dict' has no attribute 'param'

@philippjfr philippjfr added type: bug Something isn't correct or isn't working and removed TRIAGE Default label for untriaged issues labels Sep 25, 2020
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.

2 participants