交互式散景地图

时间:2019-02-02 20:57:30

标签: 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['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)

但是,我收到此警告:

警告:bokeh.embed.util: 您正在生成独立的HTML / JS输出,而是试图用实际的Python 回调(即使用on_change或on_event)。这种组合不能工作。

仅JavaScript回调可与独立输出一起使用。欲了解更多 有关使用Bokeh进行JavaScript回调的信息,请参见:

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

或者,要使用真实的Python回调,Bokeh服务器应用程序可能 使用。有关构建和运行Bokeh应用程序的更多信息,请参阅:

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

1 个答案:

答案 0 :(得分:0)

该消息试图自我说明。为了将真实的python回调连接到UI事件,必须运行一个真实的Python进程来执行回调代码。这个过程是散景服务器,并使用它,你会运行代码类似于:

def memberOnlyDetail(request, username):
    user = User.objects.get(username=username)
    skills = Skill.objects.filter(user=user)
    memberDetails =User_Model.objects.get(user=user)

    return render(request, 'memberMemberProfilePage.html', {'memberDetails': memberDetails, 'skills': skills})

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

(请注意,您还需要删除对python app.py的调用,因为它不能与Bokeh服务器应用程序一起使用。)

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

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

相关问题