Python 如何使用';轻触';在bokeh中,在不同的绘图(或表格)中进行更改?
我正在尝试创建一个bokeh仪表板(仅使用Python 如何使用';轻触';在bokeh中,在不同的绘图(或表格)中进行更改?,python,bokeh,Python,Bokeh,我正在尝试创建一个bokeh仪表板(仅使用python,而不是JS!),通过单击一个绘图中的图示符,它会影响同一仪表板中表格的输出。出于某种原因,我可以单击并选择该点,但我看不到表中有任何更改。(也因为某些原因,它没有打印到控制台,所以我发现很难调试(?)我尝试了许多不同的事情,但都没有成功。如果有人能提供任何意见,我将不胜感激。代码如下。下面的代码存在于名为“main.py”的文件夹中,该文件夹名为“select\u exp”。bokeh服务器是通过以下方式启动的: bokeh服务选择体验。
python
,而不是JS
!),通过单击一个绘图中的图示符,它会影响同一仪表板中表格的输出。出于某种原因,我可以单击并选择该点,但我看不到表中有任何更改。(也因为某些原因,它没有打印到控制台,所以我发现很难调试(?)我尝试了许多不同的事情,但都没有成功。如果有人能提供任何意见,我将不胜感激。代码如下。下面的代码存在于名为“main.py”
的文件夹中,该文件夹名为“select\u exp”
。bokeh服务器是通过以下方式启动的:
bokeh服务选择体验。
再次感谢您的帮助!
基诺
`
`在Bokeh v1.0.4中,您需要将回调应用于
数据源的选定的属性和索引属性。使用bokeh serve--show app.py运行代码
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.models.widgets import DataTable, TableColumn
# Create data for plot
x = [0, 1]
y = [0, 1]
table_index = [0, 1]
# 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))
renderer = plot.circle('x', 'y', source = plot_source, size = 30)
# Create two sets of data for the tablet
master_data = {}
master_data[0] = {'animals': ['dog', 'cat', 'cow', 'mouse'],
'plants': ['carrot', 'catnip', 'grass', 'cheese']}
master_data[1] = {'animals': ['elephant', 'lion', 'monkey', 'emu'],
'plants': ['grass', 'turnips', 'banana', 'petunias']}
# Create a table
data = master_data[0]
table_source = ColumnDataSource(data)
columns = [ TableColumn(field = 'animals', title = 'Animal'),
TableColumn(field = 'plants', title = 'Plant') ]
data_table = DataTable(source = table_source, columns = columns,
width = 400, height = 600)
# Here the reactions of the server are defined
def my_tap_handler(attr, old, new):
index = new[0]
data_table.source = ColumnDataSource(master_data[index])
plot_source.selected.on_change("indices", my_tap_handler)
# Collect it all together in the current doc
curdoc().add_root(column(plot, data_table))
curdoc().title = 'Select experiment'
结果:
它可以工作!非常感谢你,托尼。我只是想知道我会在什么文件中找到这些信息,这样下次我就不用问问题了,而是自己去弄清楚。再次感谢。请看一看,它会对您有所帮助。一般来说,它没有很好的文档记录,所以您需要分析几个示例来了解这些内容。在此特定示例中,selected
是的一个属性,它保存有关选定索引的信息。
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.models.widgets import DataTable, TableColumn
# Create data for plot
x = [0, 1]
y = [0, 1]
table_index = [0, 1]
# 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))
renderer = plot.circle('x', 'y', source = plot_source, size = 30)
# Create two sets of data for the tablet
master_data = {}
master_data[0] = {'animals': ['dog', 'cat', 'cow', 'mouse'],
'plants': ['carrot', 'catnip', 'grass', 'cheese']}
master_data[1] = {'animals': ['elephant', 'lion', 'monkey', 'emu'],
'plants': ['grass', 'turnips', 'banana', 'petunias']}
# Create a table
data = master_data[0]
table_source = ColumnDataSource(data)
columns = [ TableColumn(field = 'animals', title = 'Animal'),
TableColumn(field = 'plants', title = 'Plant') ]
data_table = DataTable(source = table_source, columns = columns,
width = 400, height = 600)
# Here the reactions of the server are defined
def my_tap_handler(attr, old, new):
index = new[0]
data_table.source = ColumnDataSource(master_data[index])
plot_source.selected.on_change("indices", my_tap_handler)
# Collect it all together in the current doc
curdoc().add_root(column(plot, data_table))
curdoc().title = 'Select experiment'