Python Bokeh图不随数据表中单击列值而动态更改

Python Bokeh图不随数据表中单击列值而动态更改,python,Python,我试图通过单击bokeh数据表中的值来更改NetworkX图形。我可以在布局框中看到并可视化所需的值,但无法使用相同的值来显示/更改NetworkX图形 我尝试过使用python回调,但它也不起作用,它说“只有JavaScript回调可以用于独立输出” 没有给出错误消息,输出显示正确的bokeh数据表,单击customer no在布局框中显示正确的值,但networkx显示黑色三角形 我可以用python回调来实现这一点。有人能帮我用CustomJS实现同样的功能吗。代码如下 from date

我试图通过单击bokeh数据表中的值来更改NetworkX图形。我可以在布局框中看到并可视化所需的值,但无法使用相同的值来显示/更改NetworkX图形

我尝试过使用python回调,但它也不起作用,它说“只有JavaScript回调可以用于独立输出”

没有给出错误消息,输出显示正确的bokeh数据表,单击customer no在布局框中显示正确的值,但networkx显示黑色三角形

我可以用python回调来实现这一点。有人能帮我用CustomJS实现同样的功能吗。代码如下

from datetime import date
from random import randint
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
import bokeh.layouts as layouts
import bokeh.models.widgets as widgets
from bokeh.io import curdoc
from bokeh.io import vplot
from bokeh.plotting import figure
from bokeh.models.graphs import 
from_networkx,NodesAndLinkedEdges,EdgesAndLinkedNodes
from bokeh.plotting import  figure
from bokeh.models import Plot,Range1d
from bokeh.io import output_file, show
from datetime import date
from random import randint
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
import bokeh.layouts as layouts
import bokeh.models.widgets as widgets
from bokeh.io import curdoc

G = nx.Graph()
G.add_nodes_from([1,2,3,4,5,6,7,8,9,10])
G.add_edges_from([(1, 2), (1, 3),(3,4),(5,6),(6,7),(8,9),(9,10)])
data = dict(
    CUSTOMER_NO=[1,2,3,4,5,6,7,8,9,10],
    priority=[1,2,3,4,5,6,7,8,9,10],
)

d_source= ColumnDataSource(data)
columns = [TableColumn(field = "CUSTOMER_NO", title = "CUSTOMER_NO"), TableColumn(field = "priority", title = "PRIORITY")]
data_table = DataTable(source = source, columns = columns, width = 200, height = 280, editable = True, reorderable = False)

def table_select_callback(attr, old, new):
    # print 'here'
    # print new
    # selected_row = new['1d']['indices'][0]
    selected_row = new[0]
    s = G.subgraph(nx.shortest_path(G.to_undirected(), data['CUSTOMER_NO'][selected_row]))
    #download_count = data['downloads'][selected_row]
    #chart_data = np.random.uniform(0, 100, size=download_count)
    plot = figure(title='test',x_range=Range1d(-1.1,1.1),y_range=Range1d(-1.1,1.1), tools = ['reset', 'pan','wheel_zoom','save', 'lasso_select', ])
    #p = figure(title='bla')
    pos=nx.random_layout(s)
    graph=from_networkx(s,pos)
    plot.renderers.append(graph)
    #r = p.line(x=range(len(chart_data)), y=chart_data)
    root_layout.children[1] = plot

d_source.selected.on_change('indices', table_select_callback)
root_layout = layouts.Column(data_table, widgets.Div(text='Select customer number'))
curdoc().add_root(root_layout)
from datetime import date
from random import randint
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
import bokeh.layouts as layouts
import bokeh.models.widgets as widgets
from bokeh.io import curdoc
from bokeh.io import vplot
from bokeh.plotting import figure
from bokeh.models.graphs import 
from_networkx,NodesAndLinkedEdges,EdgesAndLinkedNodes
from bokeh.plotting import  figure
from bokeh.models import Plot,Range1d
from bokeh.io import output_file, show
from datetime import date
from random import randint
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
import bokeh.layouts as layouts
import bokeh.models.widgets as widgets
from bokeh.io import curdoc

G = nx.Graph()
G.add_nodes_from([1,2,3,4,5,6,7,8,9,10])
G.add_edges_from([(1, 2), (1, 3),(3,4),(5,6),(6,7),(8,9),(9,10)])
data = dict(
    CUSTOMER_NO=[1,2,3,4,5,6,7,8,9,10],
    priority=[1,2,3,4,5,6,7,8,9,10],
)

d_source= ColumnDataSource(data)
columns = [TableColumn(field = "CUSTOMER_NO", title = "CUSTOMER_NO"), TableColumn(field = "priority", title = "PRIORITY")]
data_table = DataTable(source = source, columns = columns, width = 200, height = 280, editable = True, reorderable = False)

def table_select_callback(attr, old, new):
    # print 'here'
    # print new
    # selected_row = new['1d']['indices'][0]
    selected_row = new[0]
    s = G.subgraph(nx.shortest_path(G.to_undirected(), data['CUSTOMER_NO'][selected_row]))
    #download_count = data['downloads'][selected_row]
    #chart_data = np.random.uniform(0, 100, size=download_count)
    plot = figure(title='test',x_range=Range1d(-1.1,1.1),y_range=Range1d(-1.1,1.1), tools = ['reset', 'pan','wheel_zoom','save', 'lasso_select', ])
    #p = figure(title='bla')
    pos=nx.random_layout(s)
    graph=from_networkx(s,pos)
    plot.renderers.append(graph)
    #r = p.line(x=range(len(chart_data)), y=chart_data)
    root_layout.children[1] = plot

d_source.selected.on_change('indices', table_select_callback)
root_layout = layouts.Column(data_table, widgets.Div(text='Select customer number'))
curdoc().add_root(root_layout)