Python 互动博克地图

Python 互动博克地图,python,maps,bokeh,Python,Maps,Bokeh,我正在使用以下代码在python上创建一个交互式映射: # Define the callback: update_plot def update_plot(attr, old, new): # Create a dropdown Select widget for the y data: y_select N = str(select.value) map_options = GMapOptions(lat=sites_list_c.loc[sites_list_c[

我正在使用以下代码在python上创建一个交互式映射:

# Define the callback: update_plot
def update_plot(attr, old, new):

    # Create a dropdown Select widget for the y data: y_select
    N = str(select.value)
    map_options = GMapOptions(lat=sites_list_c.loc[sites_list_c['Site Name'] == N,'Latitude Decimal'], lng=sites_list_c.loc[sites_list_c['Site Name'] == N,'Lontitude Decimal'], map_type="roadmap", zoom=4)
    plot = gmap(my_key, map_options, title="Test")
    source = ColumnDataSource(
        data=dict( lat=sites_list_c['Latitude Decimal'].tolist(),
        lon=sites_list_c['Longitude Decimal'].tolist()
        )       
    )
    plot.circle(x="lon", y="lat", size=15, fill_color='blue', fill_alpha=0.8, source=source)

# Attach the update_plot callback to the 'value' property of y_select
select.on_change('value', update_plot)

# Create layout and add to current document
layout = row(widgetbox(select), plot)
curdoc().add_root(layout)
show(layout)
但是,我得到了这个警告:

WARNING:bokeh.embed.util:
You are generating standalone HTML/JS output, but trying to use real Python
callbacks (i.e. with on_change or on_event). This combination cannot work.

Only JavaScript callbacks may be used with standalone output. For more
information on JavaScript callbacks with Bokeh, see:

   http://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html

Alternatively, to use real Python callbacks, a Bokeh server application may
be used. For more information on building and running Bokeh applications, see:

http://docs.bokeh.org/en/latest/docs/user_guide/server.html

该消息试图不言自明。为了将真正的python回调连接到UI事件,必须运行一个真正的python进程来执行回调代码。该进程就是Bokeh服务器,要使用它,您可以运行类似于以下内容的代码:

bokeh serve --show app.py
更具体地说,您不会只执行
python app.py

(注意,您还需要删除对
show
的调用,因为它不适用于Bokeh服务器应用。)

否则,如果您只是像普通python脚本一样运行它(并使用
show
调用),那么Bokeh将生成静态HTML+JS输出。在这种情况下,Python回调无法执行,因为输出仅在web浏览器中显示,web浏览器无法运行Python代码。唯一可以运行的回调类型是JavaScript回调

在文档的章节中有大量关于运行Bokeh服务器应用程序的文档,在章节中有大量关于
CustomJS
callbacks的文档