I have a scatter plot, each point represents a location and is connected to a timeseries of the Resistance measured in that point. I want to make a app where I select a point with the scatterplot on top and the timeseries graph below. If I select a point in the scatterplot, using the tap tool, I want the bottom graph to automatically change.
I was able to do this with a python callback but need it in CustomJS (my aim is to create a dashboard and I have other modules already in CustomJS)
I’m not at liberty to disclose my data yet so below is a simplified version
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
# Create data for plot
x = [0, 1, 2]
y = [0, 1, 4]
# Create the plot (this will be clicked on)
plot = figure(height=400, width=600, title='Select a point', tools='tap')
plot_source = ColumnDataSource(data=dict(x=x, y=y))
plot.circle('x', 'y', source=plot_source, size=30)
# Create two sets of data for the graph
master_data = {0: {'x': [0, 1, 2], 'y': [0, 1, 4]},
1: {'x': [0, 1, 2], 'y': [0, -1, -4]},
2: {'x': [0, 1, 2], 'y': [0, 2, 8]}}
# Create a graph
data = master_data[0]
graph_source = ColumnDataSource(data)
graph = figure(height=400, width=600, title='Graph', tools='')
graph.line('x', 'y', source=graph_source)
# Here the reactions of the server are defined
def my_tap_handler(attr, old, new):
index = new[0]
graph_source.data = master_data[index]
plot_source.selected.on_change("indices", my_tap_handler)
curdoc().add_root(column(plot, graph))
This is the callback I tried but did not work
callback_code = """
const index = cb_obj.indices[0];
graph_source.data = master_data[index];
graph_source.change.emit();
"""
# Create a CustomJS callback using the code
callback = CustomJS(args=dict(graph_source=graph_source, master_data=master_data), code=callback_code)