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

Added support for selecting lists and dicts #50

Merged
merged 4 commits into from
Sep 20, 2018
Merged

Added support for selecting lists and dicts #50

merged 4 commits into from
Sep 20, 2018

Conversation

jbednar
Copy link
Member

@jbednar jbednar commented Sep 20, 2018

Selector widgets currently need to do a reverse lookup on object identity, which requires that objects be hashable, which Bokeh palettes (as lists) are not. This PR and a matching PR on param converts lists to tuples when doing lookups, which works:

import panel as pp
from colorcet import kbc, fire
pp.extension()

def fn(a=1.7, cmap=kbc):
    return a,cmap[0]

pp.interact(fn, cmap=[kbc,fire])

image

import param

class C(param.Parameterized):
    a = param.Number(1.7, bounds=(-2, 2))
    cmap = param.ObjectSelector(kbc,[kbc,fire])

    def view(self):
        return self.a, self.cmap[0]
c=C()
pp.Row(c.param,c.view)

image

However, note that in both cases the representation of the list is vastly larger than the widget box, which in the second example ends before (2, '#000000') starts. @philippjfr, is there a way to truncate the representation in the widget when it's longer than the box?

For a Param-based widget the solution is to provide string names, but I'm not sure how to do that with interact:

class C(param.Parameterized):
    a = param.Number(1.7, bounds=(-2, 2))
    cmap = param.ObjectSelector(kbc,dict(kbc=kbc,fire=fire))

    def view(self):
        return self.a, self.cmap[0]
c=C()
pp.Row(c.param,c.view)

image

@codecov-io
Copy link

codecov-io commented Sep 20, 2018

Codecov Report

Merging #50 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #50      +/-   ##
==========================================
+ Coverage   91.14%   91.22%   +0.07%     
==========================================
  Files          23       23              
  Lines        2925     2950      +25     
==========================================
+ Hits         2666     2691      +25     
  Misses        259      259
Impacted Files Coverage Δ
panel/param.py 91.25% <100%> (ø) ⬆️
panel/tests/test_widgets.py 100% <100%> (ø) ⬆️
panel/widgets.py 97.54% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2111d7...bdc9e66. Read the comment docs.

@philippjfr
Copy link
Member

Looks good. Want to add a unit test? 😄

@jbednar
Copy link
Member Author

jbednar commented Sep 20, 2018

Also added support for selecting dicts:

import param

theme1 = dict(a=2,c=5)
theme2 = dict(a=5,c=2)

class C(param.Parameterized):
    a = param.Number(1.7, bounds=(-2, 2))
    theme = param.ObjectSelector(theme1,{"1":theme1,"2":theme2})

    def view(self):
        return self.a, self.theme
c=C()
pp.Row(c.param,c.view)

image

@jbednar jbednar changed the title Added support for selecting lists Added support for selecting lists and dicts Sep 20, 2018
@philippjfr philippjfr merged commit 46dc8df into master Sep 20, 2018
@jbednar
Copy link
Member Author

jbednar commented Sep 20, 2018

For a Param-based widget the solution is to provide string names, but I'm not sure how to do that with interact

Actually, the same solution works with interact too:

import panel as pp
from colorcet import kbc, fire
pp.extension()

def fn(a=1.7, cmap=kbc):
    return a,cmap[0]

pp.interact(fn, cmap=dict(kbc=kbc,fire=fire))

image

So it is still an error that the widget extends outside the widget box, but at least there's a workaround that's arguably the right thing to do anyway (use string names for any complex objects).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants