滑块值未更新Bokeh Python

滑块值未更新Bokeh Python,python,python-3.x,slider,bokeh,interactive,Python,Python 3.x,Slider,Bokeh,Interactive,我正在努力用Bokeh在Jupyter笔记本上制作一个互动情节。我想绘制一张世界地图,并显示一些数据随时间的发展。我成功地绘制了一个图,并用一个滑块来调整年份,但当我更改滑块时,滑块值不会更新。滑块的代码如下所示: #creating the data source as a dict source = ColumnDataSource({ 'x': p_df['x'], 'y': p_df['y'], 'Country': p_df['Country'],

我正在努力用Bokeh在Jupyter笔记本上制作一个互动情节。我想绘制一张世界地图,并显示一些数据随时间的发展。我成功地绘制了一个图,并用一个滑块来调整年份,但当我更改滑块时,滑块值不会更新。滑块的代码如下所示:

#creating the data source as a dict
source = ColumnDataSource({
    'x': p_df['x'], 
    'y': p_df['y'], 
    'Country': p_df['Country'], 
    'nkill': p_df['nkill']
})

#making a slider and assign the update_plot function to changes
slider = Slider(start=start_yr, end=end_yr, step=1, value=start_yr, title='Year')
slider.on_change('value',update_plot)

#the update_plot function which needs to run based on the new slider.value
def update_plot(attr, old, new):
    #Update glyph locations
    yr = slider.value
    Amountkills_dt_year = p_df[p_df['Year'] ==yr]
    new_data = {
        'x': Amountkills_dt_year['x'], 
        'y': Amountkills_dt_year['y'], 
        'Country': Amountkills_dt_year['Country'], 
        'nkill': Amountkills_dt_year['nkill']
    }
    source.data = new_data
    #Update colors
    color_mapper = LinearColorMapper(palette='Viridis256',
                                 low = min(Amount_of_Terrorist_Attacks['nkill']),
                                 high = max(Amount_of_Terrorist_Attacks['nkill']))

我想用update_plot()函数更新绘图。我试过解决这个问题,但还是遇到了同样的错误

像Slider这样的Bokeh小部件在jupyter笔记本电脑中不起作用(至少,如果不使用一些javascript的话)。正如政府所说:

根据@bigreddot的提示,您需要使用bokeh服务器或其他服务器
可能是jupyter Interactions讨论中讨论的一些功能。

您是否将此作为Bokeh服务器应用程序运行,即使用
Bokeh serve app.py
?不,我正在jupyter笔记本中运行我的应用程序,并使用
show()
绘制地图,我猜可能使用
show()
生成一个静态绘图,而不是可以与我的滑块交互的绘图…Bokeh小部件和Bokeh服务器应用程序可以在笔记本中使用,但您必须以特定的方式进行操作。请参见repo中的notebook_embed.ipynb示例。
To use widgets, you must add them to your document and define their functionality. Widgets can be added directly to the document root or nested inside a layout. There are two ways to program a widget’s functionality:

        Use the CustomJS callback (see JavaScript Callbacks). This will work in standalone HTML documents.

        Use bokeh serve to start the Bokeh server and set up event handlers with .on_change (or for some widgets, .on_click).