
I want to be able to change the palette using select.
Below is an example of my attempt. I just want to change the palette by taking the values out of the box.
import numpy as np
from bokeh.plotting import figure, show
from bokeh.models import Row
from bokeh.models import LinearColorMapper, BasicTicker, ColorBar, Select,CustomJS
from bokeh.models.widgets import RangeSlider
import bokeh
data = np.random.rand(10,10)
select = Select(title="Palette:", options=["Viridis256","Magma256"])
color_mapper = LinearColorMapper(palette=select.options[0], low=0, high=1)
figure = figure(x_range=(0,1), y_range=(0,1))
img = figure.image(image=[data], color_mapper=color_mapper,
dh=[1.0], dw=[1.0], x=[0], y=[0])
color_bar = ColorBar(color_mapper=color_mapper, ticker= BasicTicker(),
location=(0,0))
figure.add_layout(color_bar, 'right')
cmap_callback = CustomJS(args=dict(img=img), code='''
img.glyph.color_mapper.palette=this.value;
''')
select.js_on_change( 'value',cmap_callback)
show(Row(figure, select ))
However, the selection doesn’t work. The console displays the following:
![]()
I do not understand what the problem is, because I’m passing exactly what he considers invalid. Most likely the problem is in js. I have no proper experience with this language.


