I’m trying to show the ‘name
’ of image
upon single tap with ColumnDataSource
using CustomJS
.
I’m accessing the ‘name
’ using source.data['name']
. It should be quite straight forward, but I just can’t get it to work. Could any one please help look what is wrong with my script? Thanks!
from bokeh.plotting import figure, show
from bokeh.models import TextInput, CustomJS
from bokeh.models import ColumnDataSource
from bokeh.events import Tap
from bokeh.layouts import column
import numpy as np
ramp = np.array([np.linspace(0, 10, 200)]*20)
steps = np.array([np.linspace(0, 10, 10)]*20)
bitmask = np.random.rand(25, 10) > 0.5
source = ColumnDataSource(dict(image=[ramp, steps, bitmask],
name=['ramp', 'steps', 'bitmask'],
x=[0, 0, 25],
y=[5, 20, 5],
dw=[20, 20, 10],
dh=[10, 10, 25]))
p = figure( x_range=(0, 35), y_range=(0, 35), tools='wheel_zoom')
p.image(source=source, image='image', x='x', y='y', dw='dw', dh='dh', name='name', palette="Inferno256")
text_name = TextInput(title='name', value='', disabled=True)
text_name_cb = CustomJS(args=dict(text_name=text_name, source=source), code="""
text_name.value = source.data['name'];
""")
p.js_on_event(Tap, text_name_cb)
show(column(p, text_name))