由于跨域问题,我无法在部署的服务器上使用bokeh图。我已经以几种形式提出了这个问题,但实际上并没有解决。

我总是得到错误

XMLHttpRequest cannot load http://127.0.0.1:5006/bokeh/objinfo/0257493b-cce5-450d-8036-2bc57233b1dc/bd1791f4-4d28-4faa-8c9d-a6fe5a1721c1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://my_ip_address' is therefore not allowed access. The response had HTTP status code 500.


无论是运行applet还是试图嵌入单个图。

在这里,我试图从Flask视图中获取绘图脚本

@perf.route('/_fetch_heatmap', methods=['POST'])
@login_required
def fetch_sd_heatmap():

    document = Document()
    session = Session(root_url='http://127.0.0.1:5006', configdir=current_app.config['BASE_DIRECTORY'])
    session.use_doc('sd_viz')
    session.load_document(document)
    ...
    plots = VBox(hm_duration, hm_frequency)

    document.add(plots)
    push(session, document)

    script = autoload_server(plots, session)

return jsonify({'script': script})


该脚本返回到我的JavaScript中的ajax调用。然后将此脚本附加到相应的<div>

这在我的开发机器上运行良好。

以下是我用于生产的Nginx配置

server {


    listen my_ip default_server;
    charset     utf-8;
    client_max_body_size 30M;

    location ~ ^/(app_config.py|.git) {
        deny all;
        return 404;
    }

    location / {
        index index.html index.htm;
        root /home/myuser/app_directory;
        try_files $uri @app;
    }

    location /static {
    alias /home/myuser/app_directory/webapp/static;
    }


    location @app {
        include uwsgi_params;
        uwsgi_pass unix:/home/myuser/app_directory/uwsgi.sock;
        uwsgi_connect_timeout 18000;
...
}


有没有人成功地在生产环境中运行的bokeh服务器上制作了带有嵌入式bokeh图的flask应用程序?

最佳答案

您好,只是为了更新此讨论,从0.11中的新Bokeh服务器开始,有更多有关部署的文档:

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

包括有关使用反向代理运行,使用负载平衡器和流程管理器以及使用Salt等工具实现自动化的信息。 never服务器更加健壮,可扩展且易于使用。您可以在此处看到自2016年1月以来一直“生产”部署的实时Bokeh服务器示例库:

http://demo.bokeh.org

作为参考,可以在GitHub上研究完整的自动化部署:

https://github.com/bokeh/demo.bokeh.org

此外,此处的“幸福”示例中展示了一个嵌入特定于会话的Bokeh服务器应用程序的相当复杂的示例:

https://github.com/bokeh/bokeh/tree/master/examples/embed/server_session

但最后我要说的是,upcoiming 0.12版本将能够为Bokeh应用程序设置自定义Jinja模板,这意味着可以在不使用Bokeh服务器的情况下直接从Bokeh服务器提供服务,例如可以大量围绕Bokeh文档构建的Single Page Apps之类的东西。嵌入到另一个Web服务器中(如果需要)。

关于python - 无法使bokeh服务器在服务器上运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33356654/

10-13 07:40