Estoy tratando de usar taptool para otra devolución de llamada de la trama, he estado destrozando mi cabeza por un buen tiempo. Tengo dos parcelas y dos fuentes diferentes. Encuentre un ejemplo mínimo a continuación:
Tengo un diagrama de 7 círculos en una figura, me gustaría poder tocarlos y usarlos como devolución de llamada a otros diagramas. Probé con source.indices, pero hasta ahora estoy atascado.
Basado en el enlace bigredot.
https://www.py4u.net/discuss/194426
from bokeh.layouts import row from bokeh.models import ColumnDataSource, CustomJS, TapTool from bokeh.plotting import figure, show import numpy as np source_bars = ColumnDataSource({'x': [1, 2, 3], 'y': [2, 4, 1] , 'colnames': ['A', 'B', 'C']}) lines_y = [np.random.random(3) for i in range(3)] src1 = ColumnDataSource(data=dict(x= [1, 2, 3], y=lines_y[0], y2=lines_y[1], y3=lines_y[2])) plot1 = figure(tools = 'tap') bars = plot1.vbar(x = 'x', top = 'y', source = source_bars, bottom = 0, width = 0.5) plot2 = figure() lines = plot2.vbar(x = 'x', top = 'y', source = src1) code = '''if (cb_data.source.selected.indices.length > 0){ var data = lines_y.data var selected_index = cb_data.source.selected.indices[0]; lines.data_source.data['y'] = lines_y[selected_index] lines.data_source.change.emit(); }''' plots = row(plot1, plot2) plot1.select(TapTool).callback = CustomJS(args = {'lines': lines, 'lines_y': src1}, code = code) show(plots) Un enfoque diferente con este código, pero!!!
code3 = """ var col = 'Muara_Teweh_'; // Get data from CDS var data = source.data; var data1 = source1.data; var selected = source.selected.indices; // Iterate over all entries in the CDS for (var i=0; i<data[col].length; i++){ if(data[col][i]!=selected){ data1[selected]; } } } // Save changes to CDS source.change.emit(); source1.change.emit(); """Gracias.