【问题标题】:Interactive Bokeh Map交互式散景地图
【发布时间】:2019-02-02 20:57:30
【问题描述】:

我正在使用此代码在 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 maps bokeh


    【解决方案1】:

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

    bokeh serve --show app.py
    

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

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

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

    在文档的 Running a Bokeh Server 章节中有大量关于运行 Bokeh 服务器应用程序的文档,在 JavaScript Callbacks 章节中有关于 CustomJS 回调的大量文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 2016-12-18
      • 2019-07-23
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多