
This code works if you set the callback to the selected on change. But what i want is the ability to select points then push it to another source, only if the button is pressed. But js_on_click only takes 2 positional arguments. Is it not possible to push data to another source with a button click?
from bokeh.io import output_file, show
from bokeh.layouts import row
from bokeh.models import ColumnDataSource, CustomJS, Button, TableColumn, DataTable
from bokeh.plotting import figure, output_notebook
output_notebook()
x1 = list(range(-20, 21))
y1 = [abs(xx) for xx in x]
# create a column data source for the plots to share
s1 = ColumnDataSource(data=dict(x1=x1, y1=y1))
s2 = ColumnDataSource(data=dict(x2=[], y2=[]))
TOOLS = "box_select,lasso_select,help"
# create a new plot and add a renderer
left = figure(tools=TOOLS, plot_width=300, plot_height=300, title=None)
left.circle(x='x1', y='y1', source=s1)
# create another new plot and add a renderer
right = figure(tools=TOOLS, plot_width=300, plot_height=300, title=None)
right.circle(x='x2', y='y2', source=s2)
callback = """
var inds = cb_obj.indices;
var d1 = s1.data;
var d2 = s2.data;
for (var i = 0; i < inds.length; i++) {
d2['x2'].push(d1['x1'][inds[i]])
d2['y2'].push(d1['y1'][inds[i]])
}
s2.change.emit();
"""
s1.selected.js_on_change('indices', CustomJS(args=dict(s1=s1, s2=s2)))
columns = [TableColumn(field ='x2', title = "x2"),
TableColumn(field ='y2', title = "y2")
]
table = DataTable(source=s2,
columns=columns,
width=200,
height=300,
)
PushButton = Button(label="Push", width=80)
PushButton.js_on_click('indices', CustomJS(args=dict(s1=s1, s2=s2),code=callback))
p = row(PushButton, left, right, table)
show(p)

