Hi,
I am trying to make a tap tool with two different behaviors depending on whether the user is clicking on a point or control + clicking a point.
I would like this so that the user can tap for one type of behavior, but also control + click to open a URL associated with the point.
My example to start with that does not have this feature, it just opens the link when you press the points:
from bokeh.models import CustomJS, TapTool, ColumnDataSource
from bokeh.plotting import figure, show
cds = ColumnDataSource({
'x': [1, 2, 3],
'y': ['a', 'b', 'c'],
'link': ['www.google.com', 'www.bing.com', 'www.cnn.com']
})
plot = figure(width=300, height=300, y_range=['a', 'b', 'c'])
plot.scatter(x='x', y='y', color="#fa9fb5", source=cds,
marker='triangle_pin', size=15)
code = """
window.open('http://'.concat(cb_data.source.data.link[cb_data.source.inspected.indices]), '_blank')
"""
callback = CustomJS(args=dict(), code=code)
tap_tool = TapTool(behavior='inspect', callback=callback)
plot.add_tools(tap_tool)
show(plot)
I want to adjust the callback code to be something like this:
code = """
console.log(window)
console.log(MouseEvent.ctrlKey)
if (MouseEvent.ctrlKey) {
window.open('http://'.concat(cb_data.source.data.link[cb_data.source.inspected.indices]), '_blank')
} else {
// do something different
}
"""
But I am not sure how exactly to know if control key was pressed, since MouseEvent.ctrlKey is undefined.
I’m wondering if I can somehow get to this information via window
? Any help is appreciated! Thanks in advance.
Edit: I am using bokeh 2.4.2