代码之家  ›  专栏  ›  技术社区  ›  znstrider

Bokeh-更新渲染器和DataTable的源-使用回调?

  •  0
  • znstrider  · 技术社区  · 7 年前

    我最近开始学习bokeh,我完全无法让回调工作。

    我想做的是使用PointDrawTool更新源代码。它确实会更新绘图和表格,但显然不会更新渲染器或源。这让我非常困惑,我希望能得到一些帮助。

    我的工作如下:

    from bokeh.models.glyphs import Circle
    from bokeh.plotting import figure, show, output_notebook, Column, Row
    from bokeh import events
    from bokeh.models import DataTable, TableColumn, PointDrawTool, ColumnDataSource, CustomJS
    
    output_notebook()
    
    p = figure(width = 400, height = 600)
    
    source = ColumnDataSource({
        'x': [38], 'y': [-12], 'color': ['red']
    })
    
    renderer = p.circle(x='x', y='y',
                        source=source,
                        color='color',
                        size=10)
    
    columns = [TableColumn(field="x", title="x"),
               TableColumn(field="y", title="y"),
               TableColumn(field='color', title='color')]
    
    table = DataTable(source=source, columns=columns, editable=True, height=200)
    
    draw_tool = PointDrawTool(renderers=[renderer],
                              empty_value='red')
    
    p.add_tools(draw_tool)
    p.toolbar.active_tap = draw_tool
    
    show(Row(p,table))
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Toby Petty    7 年前

    使用绘制图表的方法( show )无法更新图表的源代码(除非编写自定义JavaScript)。为了实现这一点,您需要使用Bokeh服务器,如下所述 here

    基本上,将所有代码放在一个名为“main”的文件中。py',然后将其保存在项目名称所在的文件夹中。然后在终端运行中

    bokeh serve --show project_name
    

    我以前没有使用过PointDrawTool,但如果它是一个小部件,还需要编写函数来编程如何更新源数据,使用 on_click on_change 描述的方法 here