在烧瓶中嵌入散景应用程序 [英] Embedding a bokeh app in flask
问题描述
我拼命地尝试将一个工作散景小程序嵌入烧瓶中,但找不到合适的方法来做到这一点.我查看了所有示例,但找不到包含更新数据功能的示例(最佳示例:slider_applet).
I am trying desperately to embed a working bokeh applet into flask, and can't find a proper way to do this. I looked through all the examples, but I can't find one which includes the ability to update the data (best example: the sliders_applet).
如果我没记错的话,我确实需要散景服务器才能更改数据(使用滑块等).以这种方式启动小程序是有效的,例如:
If I'm not mistaken, I do need the bokeh-server to be able to change the data (with sliders etc.). Starting the applet this way works, e.g.:
bokeh-server --script sliders_app.py
但我找不到合适的方法,或者至少找不到将滑块应用程序嵌入烧瓶的工作方法.而且由于应该可以使用多个小程序,因此在散景服务器启动时也指定一个小程序对我来说似乎并不干净..
But I can't find the proper, or at least a working way to embed the sliders_app into flask. And since it should be possible to use multiple applets, it doesn't seem clean to me to specify one single applet at the startup of the bokeh server too..
我很乐意提供任何帮助 - 散景对我来说是一个很棒的工具.
I would gladly appreciate any help - bokeh looks like a great tool for me.
推荐答案
另一个答案没有描述如何嵌入 Bokeh 服务器应用程序(它使用 components
嵌入独立的 Bokeh 文档).
The other answer does not describe how to embed a Bokeh server app (it uses components
to embed a standalone Bokeh document).
首先,您可以在以下位置看到许多现场示例:https://demo.bokeh.org/一个>
First, you can see lots of live examples hosted at: https://demo.bokeh.org/
对于嵌入应用程序,有两个常用选项:
For embedding apps there are two usual options:
- iframes(工作正常),或
server_document
后者通常是这样使用的:
The latter is usually used like this:
from bokeh.embed import server_document
script = server_document("https://demo.bokeh.org/sliders")
这将返回一个类似于下面的 标签,您可以将其放入您的 Flask HTML 响应中,无论您希望应用出现在何处:
This will return a <script>
tag similar to the one below, that you can put in your flask HTML response, wherever you'd like the app to appear:
<script
src="https://demo.bokeh.org/sliders/autoload.js?bokeh-autoload-element=1000&bokeh-app-path=/sliders&bokeh-absolute-url=https://demo.bokeh.org/sliders"
id="1000">
</script>
最后,请务必注意,默认情况下 Bokeh 服务器选择相当保守的网络配置.您需要将 --allow-websocket-origin
命令行选项设置为您要将散景应用程序嵌入到的任何主机来启动散景服务器.
Lastly, it's important to note that by default the Bokeh server opts for a fairly conservative network configuration. You'll need to start the Bokeh server with --allow-websocket-origin
command line option set to be whatever host you are embedding the bokeh app into.
这篇关于在烧瓶中嵌入散景应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!