bokeh服务器如何从server_document()访问参数 [英] how can a bokeh server access arguments from server_document()

查看:113
本文介绍了bokeh服务器如何从server_document()访问参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Flask应用程序,可与bokeh服务器对话.

I have a flask app which talks to a bokeh server.

我想将参数传递给bokeh服务器,以便bokeh服务器可以使用该信息来不同地显示事物.

I want to pass arguments to the bokeh server so that the bokeh server can use that information to display things differently.

这是我的烧瓶路线,以及我尝试将参数传递给bokeh的方式:

Here's my flask route, complete with how I'm attempting to pass arguments to bokeh:

@app.route('/test')
def test():
    return render_template(
        'bokeh.html', 
        template='Flask',
        script=server_document(
            url='http://localhost:6001/test',
            arguments={'foo': 'bar'}
    ))

我认为我正确传递了参数,但是我不知道如何在bokeh服务器上访问这些参数.所以我实际上不知道他们是否能到达那里,但是我看不到任何错误.

I think I'm passing the arguments correctly but I don't know how to access these arguments on the bokeh server. So I don't actually know if they're getting there, but I see no errors.

我了解到server_document()返回一个JavaScript字符串:

I understand that the server_document() returns a javascript string:

<script src="http://localhost:6001/test/autoload.js?bokeh-autoload-element=1001&bokeh-app-path=/test&bokeh-absolute-url=http://localhost:6001/test&foo=bar" id="1001"></script>

因此参数被嵌入url http://localhost:6001/test&foo=bar中,但我仍然不知道bokeh服务器如何使它们可用于python代码.

So the arguments are embedded in the url http://localhost:6001/test&foo=bar but I still don't know how the bokeh server makes them available to the python code.

如何访问bokeh服务器上的参数:{'foo': 'bar'}?

How do I access the arguments: {'foo': 'bar'} on the bokeh server?

我认为我在中找到了答案从Flask api到Bokeh autoload_server ,但是我错了.

I thought I found the answer in Passing arguments to Bokeh autoload_server from Flask api but I was wrong.

当我尝试将建议的内容添加到main.ipynb文件(我们正在使用面板来提供bokeh应用程序)时,此操作无效:

When I attempted to add what was suggested to my main.ipynb file (we're using panel to serve the bokeh app) it didn't work:

main.ipynb:
...
print(doc.session_context.request.arguments)
report.serve()

导致此错误:

Error running application handler <bokeh.application.handlers.directory.DirectoryHandler object at 0x7f981b953cf8>: name 'doc' is not defined
File "main.ipynb"...
File "/conda/lib/python3.7/site-packages/bokeh/application/handlers/code_runner.py", line 179...
NameError: name 'doc' is not defined

推荐答案

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆