Bokeh 服务器:点击散点以在条形图中显示其他数据

Bokeh Server: Tap on Scatter to Show additional Data in Bar Plot

我有一个 DataFrame,它包含我想在散点图中绘制的数据。 DataFrame 包含的信息远远多于散点 x 和 y 数据所需的列。

我想将附加数据显示为悬停(这不是问题),但如果我点击-select 分散中的一个数据点,则 ColumnDataSource 的其他列中的附加数据应为条形图中的 plottet。

我的主要问题是让条形图接受存储在 ColumnDataSource 的 selected 行中的数据。 我所看到的一切都使用基于列的数据将其提供给条形图。

我在解决方法中途使用了 ColumnDatasource 的 selected 行将其转换回 DataFrame 然后转置它(因此它是基于列的)然后返回到 ColumnDataSource 但是这应该不是散景创作者的本意吧?

我将我的问题简化为一个极简代码片段:

df = pd.DataFrame({"x": [1,2,3,4,5,6],
                   "y": [6,5,4,3,2,1],
                   "cat1": [11,12,13,14,15,16],
                   "cat2": [100,99,98,97,96,95]})

SRC = ColumnDataSource(df)

def Plot(doc):
    
    def callback(event):
        SELECTED = SRC.selected.indices
        bplot = make_bPlot(SELECTED)
        
    def make_bPlot(selected):
        #Here is my question:
        #How to feed the row-wise data of the SRC to the barplot?
        b = figure(x_range=["cat1", "cat2"])
        b.vbar(x=["cat1", "cat2"], top=["cat1", "cat2"], source=SRC)
        
        return b
        
    TOOLTIPS = [
        ("x", "@x"),
        ("y", "@y"),
        ("Category 1", "@cat1"),
        ("Category 2", "@cat2")]

    TOOLS="pan,wheel_zoom,zoom_in,zoom_out,box_zoom,reset,tap"
    cplot = figure(tools = TOOLS, tooltips=TOOLTIPS)
    cplot.circle("x", "y", source=SRC)
    
    bplot = make_bPlot(None) # init
       
    
    taptool = plot.select(type=TapTool)
    cplot.on_event(Tap, callback)
    
    
    layout = column(cplot, bplot)
    doc.add_root(layout)

提前致谢。

我从 Bokeh Discourse Forum 得到了答案: https://discourse.bokeh.org/t/tap-on-scatter-to-show-additional-data-in-bar-plot/6939