Bokeh- 数据表更新标签文本(0.12.16 ->0.13.0 修复作业)

Bokeh- Datatable updating Label text (0.12.16 ->0.13.0 repair job)

我最近发现新的散景为堆叠条形图实现了更详细的悬停选项。 Giddy,我立即更新了散景并将其合并到嵌套堆叠的 vbar 中。但是我不知道,我在以前的版本中实现的一个不相关的回调不再有效,我不知道如何修复它。

我有一个数据 table,它的行有几列有数字。选择行将对每个选定行的列求和,并将其显示在 Label 中。这个方面在 0.13.0 中不再有效。请看下面的简化娱乐:

Dataframe(df):
NAME  |  Sales  |  Returns | YEAR
John      33        3        2018
Mike      12        3        2018
Jim       19        9        2018
Tim        3        1        2017
Tom       20        0        2017
import pandas as pd
from bokeh.models import (ColumnDataSource, LabelSet, TapTool, OpenURL,CustomJS, NumberFormatter,
                              TableColumn, DataTable, Slider, CDSView,HoverTool,PreText, BoxSelectTool,
                              Label, Text, Button)
from bokeh.plotting import figure
from bokeh.io import curdoc
from bokeh.layouts import layout, column
from datetime import date
from bokeh.core.properties import expr
from bokeh.palettes import Spectral10

source=ColumnDataSource(data=df)

columns=[TableColumn(field="NAME", title="NAME"),
TableColumn(field="Sales", title= "Sales"),
TableColumn(field="Returns",title="Returns")]

data_table=DataTable(source=source, columns=columns)

def statsline(attr,old,new):
    selection=source.selected.indices
    if selection:
        sales=sum(source.data['Sales'][selection])
        returns=sum(source.data['Returns'][selection])

        income.text="SELECTION | Sales: " + str(sales) + " | Returns: " + str(returns)
p_stat=figure(plot_width=1400, plot_height=60, toolbar_location=None)

income=Label(x_units='screen',y_units='screen',x=90, y=5,
             text="Sales: " + str(df["Sales"][df["YEAR"]==date.today().year].sum()) +"   |   
             Returns: " +str(df["Returns"][df["YEAR"]==date.today().year].sum()),
             text_font_size='20pt')
p_stat.add_layout(income)
source.on_change('selected', statsline)

layout=layout([p_stat],[data_table])
curdoc().add_root(layout)

提前致谢。 另外,有没有更简单的方式在散景中显示 KPI?我 运行 没主意了。

在 Bokeh 0.13.0 中有几个与 DataTable 相关的回归,它们将在下一个版本中解决。目前(但也将继续),这种模式将起作用:

source.selected.on_change('indices', ...)