我正在开发一个仪表板,用户点击一个常规散点图上的多个点中的一个来获取关于这个点的更多信息。每个点代表一组数据,当单击时,用户应该能够看到一个表,其中列出了相关的数据组。
该表将在绘图旁边列出,每次选择新的点(或多个点)时,行将发生更改。
然后,我需要在这个表中添加过滤器,所以它也需要是交互式的。在筛选过程中,图表不会更改,只有表中的相关数据才会更改。
我看到了以下示例,它实现了与我想要实现的完全相反的目标:
from bokeh.plotting import Figure, output_file, show
from bokeh.models import CustomJS
from bokeh.models.sources import ColumnDataSource
from bokeh.layouts import column, row
from bokeh.models.widgets import DataTable, TableColumn, Toggle
from random import randint
import pandas as pd
output_file("data_table_subset_example.html")
data = dict(
x=[randint(0, 100) for i in range(10)],
y=[randint(0, 100) for i in range(10)],
z=['some other data'] * 10
)
df = pd.DataFrame(data)
#filtering dataframes with pandas keeps the index numbers consistent
filtered_df = df[df.x < 80]
#Creating CDSs from these dataframes gives you a column with indexes
source1 = ColumnDataSource(df) # FIGURE
source2 = ColumnDataSource(filtered_df) # TABLE - FILTERED
fig1 = Figure(plot_width=200, plot_height=200)
fig1.circle(x='x', y='y', source=source1)
columns = [
TableColumn(field="x", title="X"),
TableColumn(field="z", title="Text"),
]
data_table = DataTable(source=source2, columns=columns, width=400, height=280)
button = Toggle(label="Select")
button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
var inds_in_source2 = source2.get('selected')['1d'].indices;
var d = source2.get('data');
var inds = []
if (inds_in_source2.length == 0) { return; }
for (i = 0; i < inds_in_source2.length; i++) {
inds.push(d['index'][i])
}
source1.get('selected')['1d'].indices = inds
source1.trigger('change');
""")
show(column(fig1, data_table, button))我尝试替换按钮回调中的source1和source2,以试图逆转筛选(即在图中选择一个点并过滤数据表)。但是数据表根本不被过滤,而只是选择了与数据点相对应的行。您知道如何筛选出在绘图中选择的而不是的其余行吗?
发布于 2017-07-06 20:12:58
我在另一个问题上找到了答案:Bokeh DataTable won't update after trigger('change') without clicking on header
显然,数据表更改也需要触发。
https://stackoverflow.com/questions/44893677
复制相似问题