.
, 1.0. 1.0, 'indices' selected " selected:
source.selected.on_change('indices', callback)
, , Bokeh 1.0.
selected :
from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource
TOOLS = "tap"
p = figure(title="Some Figure", tools=TOOLS)
source = ColumnDataSource(dict(x=[[1, 3, 2], [3, 4, 6, 6]],
y=[[2, 1, 4], [4, 7, 8, 5]], name=['A', 'B']))
pglyph = p.patches('x', 'y', source=source, color=["firebrick", "navy"],
alpha=[0.8, 0.3], line_width=2)
def callback(attr, old, new):
patch_name = source.data['name'][new['1d']['indices'][0]]
print("TapTool callback executed on Patch {}".format(patch_name))
pglyph.data_source.on_change('selected',callback)
curdoc().add_root(column(p))
Bokeh. 0.12.16
@Karel Marik , ColumnDataSource . . , source ( shift + click):
from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource
TOOLS = ["tap"]
p = figure(title="Some Figure", tools=TOOLS)
source = ColumnDataSource(dict(
x=[[1, 3, 2], [3, 4, 6, 6]],
y=[[2, 1, 4], [4, 7, 8, 5]],
name=['A', 'B'],color=["firebrick", "navy"],
alpha=[0.8,0.3],line_width=[3,3]))
pglyph = p.patches('x', 'y', color="color", alpha="alpha",
line_width="line_width", source=source)
def callback(attr, old, new):
selections = new['1d']['indices']
print("Number of selections:{}".format(len(selections)))
for index in selections:
patch_name = source.data['name'][index]
print("TapTool callback executed on Patch {}".format(patch_name))
pglyph.data_source.on_change('selected',callback)
curdoc().add_root(column(p))