Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Python bokeh CustomJS回调更新数据表小部件_Javascript_Python_Callback_Widget_Bokeh - Fatal编程技术网

Javascript Python bokeh CustomJS回调更新数据表小部件

Javascript Python bokeh CustomJS回调更新数据表小部件,javascript,python,callback,widget,bokeh,Javascript,Python,Callback,Widget,Bokeh,如何使用Select小部件更新我的DataTable小部件的值? 以下是我的示例代码: import pandas as pd from bokeh.io import show from bokeh.layout import column from bokeh.models import ColumnDataSource, CustomJS, Select from bokeh.models.widgets import DataTable, TableColumn df = pd.Dat

如何使用
Select
小部件更新我的
DataTable
小部件的值? 以下是我的示例代码:

import pandas as pd
from bokeh.io import show
from bokeh.layout import column
from bokeh.models import ColumnDataSource, CustomJS, Select
from bokeh.models.widgets import DataTable, TableColumn

df = pd.DataFrame({'a': range(10,50), 'b': range(110,150)})

source_foo = ColumnDataSource(data=df.loc[df['a'] < 25])
source_bar = ColumnDataSource(data=df.loc[df['a'] > 25])
source_fill = ColumnDataSource(data=df.loc[df['a'] < 25])

table_columns = [TableColumn(field=i, title=i) for i in ['a', 'b']]

select = Select(title='Selected value:', value='foo', options=['foo', 'bar'])

update = CustomJS(args=dict(source_fill=source_fill, source_foo=source_foo,
        source_bar=source_bar), code="""

    var data_foo = source_foo.data;
    var data_bar = source_bar.data;
    var data_fill = source_fill.data;
    var f = cb_obj.value;
    var list = ['a', 'b']

    if (f == 'foo') {
        for(var i = 0, size = list.length; i < size ; i++) {
            var e = list[i];
            delete data_fill[e];
            data_fill[e] = data_foo[e];
        }
    }
    if (f == 'bar') {
        for(var i = 0, size = list.length; i < size ; i++) {
            var e = list[i];
            delete data_fill[e];
            data_fill[e] = data_bar[e];
        }
    }

    source_fill.change.emit();
    """)

select.js_on_change('value', update)

data_table = DataTable(source=source_fill, columns=table_columns, width=150,
    height=300, row_headers=False, selectable=False)

layout = column(select, data_table)

bio.show(layout)
将熊猫作为pd导入
来自bokeh.io导入展
从bokeh.layout导入列
从bokeh.models导入ColumnDataSource、CustomJS中,选择
从bokeh.models.widgets导入DataTable、TableColumn
数据帧({'a':范围(10,50),'b':范围(110150)})
source\u foo=ColumnDataSource(data=df.loc[df['a']<25])
source\u bar=ColumnDataSource(data=df.loc[df['a']>25])
source_fill=ColumnDataSource(data=df.loc[df['a']<25])
table_columns=[TableColumn(field=i,title=i)表示['a','b']中的i]
选择=选择(title='Selected value:',value='foo',options=['foo',bar'])
update=CustomJS(args=dict(source\u fill=source\u fill,source\u foo=source\u foo,
source\u bar=source\u bar),代码为“”
var data_foo=源_foo.data;
var data\u bar=来源\u bar.data;
var data\u fill=来源\u fill.data;
var f=cb_对象值;
变量列表=['a','b']
如果(f=='foo'){
对于(变量i=0,大小=list.length;i
如果
selective=False
,则数据值不会改变。如果我设置
selective=True
,则刷新第一行。如果我对
DataTable
的其中一列重新排序(不管
可选
),则值将刷新。如何自动强制刷新


谢谢大家!

您只需将
源代码填充.data
指针指向新数据即可:


如果(f=='foo'){
source\u fill.data=source\u foo.data;
}
如果(f=='bar'){
source_fill.data=source_bar.data;
}

您只需将
源代码填充。数据
指针指向新数据:


如果(f=='foo'){
source\u fill.data=source\u foo.data;
}
如果(f=='bar'){
source_fill.data=source_bar.data;
}

非常感谢!!!!它工作得很好!我试过
if(f='foo'){data\u fill=data\u foo}…
但也没用。非常感谢!!!!它工作得很好!我试过
如果(f='foo'){data\u fill=data\u foo}…
但也不起作用。