如何通过“ selected.on_change()”事件更新ColumnDataSource?

时间:2019-06-15 12:18:59

标签: bokeh python-3.7

首先,我使用geogr创建了一个散点图。坐标。如果我单击这些圆圈中的一个,则该散点图旁边的第二个线图会根据我单击的圆圈显示更多信息。这意味着我必须通过一个新的线图来更新当前的ColumnDataSource。但是,如果我单击这些圆圈之一,则当前源将不会更新。线图仍显示旧Source的数据集。

我将尝试给您一个简短的例子,说明我到目前为止所做的事情:


def callback(attr, old, new):

    # Depending on what circle i've clicked i start a SQL request
    # to gain my dataset i want to plot and the new title of the diagram.

    # To change the title actually works:
    line_plot.title.text = 'new_title'

    # "source_new_values" is a ColumnDataSource created out of a 
    # SQL-request of my database.
    # To change the current source doesn't work. The line-plot is still
    # showing the old dataset. 
    source_current_values = source_new_values 


scatter_plot = figure(x_axis_label='lat', y_axis_label='lon')
scatter_plot.circle(x='long', y='lat', source=source_coordinates)

# I use the indices to identify what circle was clicked.
source_coordinates.selected.on_change('indices', callback)


line_plot = figure(x_axis_label='time', x_axis_type='datetime', 
                                        y_axis_label='values', title='title')

line_plot.line(x='date', y='value', source=source_current_values)

1 个答案:

答案 0 :(得分:0)

解决问题的方法是我无法通过ColumnDataSource来更新源,而是通过使用以下命令的Dictionary来更新源:

(x:ys)