我正在使用儀表板,用戶在常規散點圖上單擊許多點之一以獲取有關該點的更多信息。每個點代表一組數據,當點擊時,用戶應該能夠看到列出相關數據組的表格。散景圖上的可點擊的點
該表格將在該圖的旁邊列出,並且每次選擇一個新點(或多個點)時,這些行都會更改。
然後我需要添加過濾器到這張表中,所以它也需要互動。在過濾過程中,繪圖不會改變,只有表格中的相關數據。
我看到下面的例子中,這實現了我想達到完全相反:
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中和源2按鈕回調內,以試圖扭轉過濾(即選擇圖上的一個點並過濾數據表)。但數據表根本不被過濾,而是簡單地選擇與數據點對應的行。任何想法如何篩選其餘的行是而不是選擇的情節?
答案几乎肯定是,但我認爲這個問題對於SO來說太廣泛了。例如,你是否想要一個獨立的(非服務器)Bokeh文檔,或者你是否想要一個Bokeh服務器應用程序(也許你現在還不知道自己!)並不清楚!對於像這樣的更開放式的問題,需要來回對話,項目郵件列表是一個更好的資源:https://groups.google.com/a/continuum.io/forum/#!forum/bokeh – bigreddot
@bigreddot我已經包含了一個示例並進行了編輯我的問題。你可以再檢查一次嗎?如果可能出於某些其他原因,我不希望使用Bokeh服務器,但可以根據需要切換到它。謝謝您的回答! – swenia