我使用CustomJS来过滤我的表,如以下代码所示。效果很好
combined_callback_code = """
var data = source.data;
var original_data = original_source.data;
var account = account_select_obj.value;
console.log("account: " + account);
for (var key in original_data) {
data[key] = [];
for (var i = 0; i < original_data['D01_03_ZF_TRANSACTIONS_TRANS_NUM_ST'].length; ++i) {
if ((account === "ALL" || original_data['D01_03_ZF_TRANSACTIONS_TRANS_NUM_ST'][i] === account))
{
data[key].push(original_data[key][i]);
}
}
}
target_obj.change.emit();;
source.change.emit();
"""
df = collection("D01_04_RT_PHARMA_TRANS")
df1= collection("MAPPING_TABLE")
# Put dataframe to bokeh data source defined
data = dict(
D01_03_ZF_TRANSACTIONS_TRANS_NUM_ST= df["D01_03_ZF_TRANSACTIONS_TRANS_NUM_ST"]
)
source = ColumnDataSource(data)
original_source = ColumnDataSource(data)
account_list = ['ALL'] + df1["ZF_TRANSACTIONS_TRANS_NUM_ST"].unique().tolist()
account_select = Select(title="Account:", value=account_list[0], options=account_list)
def make_table_1():
# Generate table
columns = [
TableColumn(field="D01_03_ZF_TRANSACTIONS_TRANS_NUM_ST", title="CMI Pharma Account" ),
]
data_table = DataTable(source=source, columns=columns, width=1000, height=300)
# now define the callback objects now that the filter widgets exist
generic_callback = CustomJS(
args=dict(source=source,
original_source=original_source,
account_select_obj=account_select,
target_obj=data_table),
code=combined_callback_code
)
# finally, connect the callbacks to the filter widgets
account_select.js_on_change('value', generic_callback)
p = column(data_table, account_select)
return p
但是我想将account_select
与data_table
分开,以便可以将其用于其他绘图(对于多绘图有1个过滤器)。
有没有办法做到这一点?我尝试了一些方法,但没有任何反应,因为出现错误:
模型必须仅由一个文档拥有