holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.75k stars 517 forks source link

ColorMap widget should define JS value mapping #5773

Open ahuang11 opened 1 year ago

ahuang11 commented 1 year ago

https://panel.holoviz.org/reference/widgets/ColorMap.html

In the docs, the initial value is the colormap's palette, but upon selecting a new colormap from the dropdown, it becomes the name

image image

I think it causes issues with: https://discourse.holoviz.org/t/how-to-use-from-param-with-colormap-widget/6304

import param
import panel as pn
import colorcet as cc
pn.extension()

class Test(pn.viewable.Viewer):

    palettes = param.List(default=cc.b_glasbey_bw_minc_20)

    def __panel__(self):
        return pn.widgets.ColorMap.from_param(self.param.palettes)

Test()
philippjfr commented 1 year ago

Seems like entirely unrelated issues, the main one being that you're not using param correctly. The only parameter definition that will work here is a Selector as you have to define the options of the ColorMap widget for it to work:

import param
import panel as pn
import colorcet as cc
pn.extension()

class Test(pn.viewable.Viewer):

    palettes = param.Selector(objects={'glasbey': cc.b_glasbey_bw_minc_20})

    def __panel__(self):
        return pn.widgets.ColorMap.from_param(self.param.palettes)

Test()

The second "issue" you're observing is that the underlying Bokeh model uses the string name as the value of the widget so when you JS link it, it'll appear to be incorrect. This latter issues could maybe be worked around by defining a _source_transform, but is unlikely to actually be useful.

ahuang11 commented 1 year ago

Awesome!