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

AutocompleteInput does not work with param #1460

Closed
MarcSkovMadsen opened this issue Jul 2, 2020 · 2 comments · Fixed by #2874
Closed

AutocompleteInput does not work with param #1460

MarcSkovMadsen opened this issue Jul 2, 2020 · 2 comments · Fixed by #2874
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Jul 2, 2020

Panel: 0.9.5
bokeh: 2.0.2

I was trying to help a user on Discourse get the AutocompleteInput working with panel.Param and param.ObjectSelector on discourse https://discourse.holoviz.org/t/how-to-map-param-string-to-pn-widgets-autocompleteinput/914/2 but could not.

I believe there is a bug

Code

import panel as pn
import param

OBJECTS = ["China", "Thailand", "Japan"]


class App(param.Parameterized):
    string_value = param.ObjectSelector(default="China", objects=OBJECTS)

    view = param.Parameter()

    def __init__(self, **params):
        params["view"] = pn.Param(
            self,
            parameters=["string_value"],
            widgets={"string_value": pn.widgets.AutocompleteInput,},
        )
        super().__init__(**params)


App().view.servable()

Stack Trace

$ python -m panel serve 'scripts\issues\issue_autocomplete.py' --dev --show
2020-07-02 05:25:54,690 Starting Bokeh server version 2.0.2 (running on Tornado 6.0.4)
2020-07-02 05:25:54,691 User authentication hooks NOT provided (default user enabled)
2020-07-02 05:25:54,694 Bokeh app running at: http://localhost:5006/issue_autocomplete
2020-07-02 05:25:54,694 Starting Bokeh server with process id: 22920
2020-07-02 05:25:58,453 Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x000001E1F7842648>: List 'options' must be a list.
File "__init__.py", line 1376, in _validate:
raise ValueError("List '%s' must be a list."%(self.name)) Traceback (most recent
call last):
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\bokeh\application\handlers\code_runner.py", line 197, in run
    exec(self._code, module.__dict__)
  File "C:\repos\private\awesome-panel\scripts\issues\issue_autocomplete.py", line 21, in <module>
    App().view.servable()
  File "C:\repos\private\awesome-panel\scripts\issues\issue_autocomplete.py", line 16, in __init__
    widgets={"string_value": pn.widgets.AutocompleteInput,},
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\param.py", line 177, in __init__
    self._update_widgets()
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\param.py", line 234, in _update_widgets
    self._widgets = self._get_widgets()
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\param.py", line 494, in _get_widgets
    widgets += [(pname, self.widget(pname)) for pname in self._ordered_params]
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\param.py", line 494, in <listcomp>
    widgets += [(pname, self.widget(pname)) for pname in self._ordered_params]
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\param.py", line 364, in widget
    widget = widget_class(**kwargs)
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\widgets\base.py", line 60, in __init__
    super(Widget, self).__init__(**params)
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\viewable.py", line 749, in __init__
    super(Reactive, self).__init__(**params)
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\viewable.py", line 358, in __init__
    super(Viewable, self).__init__(**params)
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\panel\viewable.py", line 214, in __init__
    super(Layoutable, self).__init__(**params)
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\param\parameterized.py", line 2339, in __init__
    self.param._setup_params(**params)
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\param\parameterized.py", line 991, in override_initializationtion                                   w)
    fn(parameterized_instance,*args,**k.venv\lib\site-packages\param\parameterizew)
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\param\parameter.venv\lib\site-packages\param\parameterizeized.py", line 1202, in _setup_params
    setattr(self,name,val)
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\param\parameterize.venv\lib\site-packages\param\parameterized.py", line 296, in _f
    return f(self, obj, val)           .venv\lib\site-packages\param\__init__.py"
  File "C:\repos\private\awesome-panel\.venv\lib\site-packages\param\parameter a list."%(self.name))ized.py", line 823, in __set__         st.
    self._validate(val)
  File "C:\repos\private\awesome-panel\ction opened.venv\lib\site-packages\param\__init__.n createdpy", line 1376, in _validate
    raise ValueError("List '%s' must be a list."%(self.name))
ValueError: List 'options' must be a list.
@MarcSkovMadsen MarcSkovMadsen added the TRIAGE Default label for untriaged issues label Jul 2, 2020
@philippjfr philippjfr added type: bug Something isn't correct or isn't working and removed TRIAGE Default label for untriaged issues labels Jul 27, 2020
@slamer59
Copy link

slamer59 commented Nov 1, 2020

I also need this nice feature inside a class.
I investigate it:

  • AutoComplete is a Widget calss when I expected SingleSelectBase

  • param.ObjectSelector gives OrderedDict([('China', 'China'), ('Thailand', 'Thailand'), ('Japan', 'Japan')])}
    when options expect List as said

    options = param.List(default=[])

When forcing options to be a list in AutocompleInput

class AutocompleteInput(Widget):

    min_characters = param.Integer(default=2, doc="""
        The number of characters a user must type before
        completions are presented.""")

    options = param.List(default=[])

    placeholder = param.String(default='')

    value = param.Parameter(default=None)
    
    case_sensitive = param.Boolean(default=True)

    restrict = param.Boolean(default=True)

    _widget_type = _BkAutocompleteInput

    _rename = _AutocompleteInput_rename

    def __init__(self, **params):
        options = params.get('options')
        if isinstance(options, OrderedDict):
            params['options'] = list(params['options'].keys())
        super(AutocompleteInput, self).__init__(**params)

this works:

import panel as pn
import param
pn.extension()
OBJECTS = ["China", "Thailand", "Japan"]

class App(param.Parameterized):
    string_value = param.ObjectSelector(default="China", objects=OBJECTS)

app = App()
pn.Column(
    pn.Param(app, widgets={"string_value": pn.widgets.AutocompleteInput})
 
) 

It is not very clean to do it like this but gives an idea where it fails.

What @MarcSkovMadsen proposed does not work.

I see AutocompleInput similar to Select widgets.

@jbednar
Copy link
Member

jbednar commented Nov 1, 2020

I agree; AutocompleteInput does seem like it should fit into the Select framework.

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.

4 participants