在不单击标题的情况下,Bokeh DataTable不会在触发(“更改")后更新 [英] Bokeh DataTable won't update after trigger('change') without clicking on header

查看:63
本文介绍了在不单击标题的情况下,Bokeh DataTable不会在触发(“更改")后更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

散景版本:0.10 的Python:3.4 木星:4.x

Bokeh version: 0.10 Python: 3.4 Jupiter: 4.x

目标:创建一个仅显示从散点图中选择的数据的表

Goal: create a table that only shows data selected from a scatter plot

问题:仅在单击数据表后刷新自身 尽管有:s2.trigger('change').在Bokeh网站上的其他示例中, 情节将使用此技术更新另一种情节:请参见 http ://docs.bokeh.org/en/latest/docs/user_guide/interaction.html#customjs-for-selections

Problem: the DataTable only refreshes itself after being clicked on despite the: s2.trigger('change'). In other examples on Bokeh site one plot will update another using this technique: see http://docs.bokeh.org/en/latest/docs/user_guide/interaction.html#customjs-for-selections

如果您使用的是上述版本,则以下代码应在Jupyter笔记本中运行.

the code below should run in a Jupyter notebook if you're using the above mentioned versions.

,也谢谢您的帮助. 乔

and, thanks for any help. Joe

    from bokeh.io import output_notebook, show
    from bokeh.plotting import figure
    from bokeh.models import CustomJS, ColumnDataSource
    from bokeh.models.widgets import DataTable, TableColumn
    from bokeh.io import vform

    output_notebook()

    x = list(range(-20, 21))
    y0 = [abs(xx) for xx in x]

    # create a column data source for the plots to share
    source = ColumnDataSource(data=dict(x=x, y0=y0))
    s2 = ColumnDataSource(data=dict(x=[1],y0=[2]))

    source.callback = CustomJS(args=dict(s2=s2), code="""
            var inds = cb_obj.get('selected')['1d'].indices;
            var d1 = cb_obj.get('data');
            var d2 = s2.get('data');
            d2['x'] = []
            d2['y0'] = []
            for (i = 0; i < inds.length; i++) {
                d2['x'].push(d1['x'][inds[i]])
                d2['y0'].push(d1['y0'][inds[i]])
            }
            s2.trigger('change');
        """)


    # create DataTable

    columns = [
            TableColumn(field="x", title="x"),
            TableColumn(field="y0", title="y0"),
        ]
    dt = DataTable(source=s2, columns=columns, width=300, height=300 )

    # create a new plot and add a renderer
    TOOLS = "box_select,lasso_select,help"
    left = figure(tools=TOOLS, width=300, height=300)
    left.circle('x', 'y0', source=source)


    show(vform(left,dt))

推荐答案

CustomJS中仅触发s2更改,因此dt不变是正常的.

only s2 change is triggered in the CustomJS, so it's normal that dt doesn't change.

这将完成工作,将dt移动到JS上方,将dt传递到JS中,并触发dt:

this will do the job, dt moved above the JS, dt is passed in the JS, and dt is triggered :

dt = DataTable(source=s2, columns=columns, width=300, height=300 )
source.callback = CustomJS(args=dict(s2=s2, dt=dt), code="""
        var inds = cb_obj.get('selected')['1d'].indices;
        var d1 = cb_obj.get('data');
        var d2 = s2.get('data');
        d2['x'] = []
        d2['y0'] = []
        for (i = 0; i < inds.length; i++) {
            d2['x'].push(d1['x'][inds[i]])
            d2['y0'].push(d1['y0'][inds[i]])
        }
        console.log(dt);
        s2.trigger('change');
        dt.trigger('change');
    """)

这篇关于在不单击标题的情况下,Bokeh DataTable不会在触发(“更改")后更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆