由於bigreddot表示,工作流程與代碼中的細微變化非常相似。我實際上是根據他的口吻建立了我的答案。謝謝bigreddot!
以下是我的解決方案集成散景服務與金字塔。
- 創建一個函數,以產生散景文件(曲線)
def bokeh_doc(doc):
# create data source
# define all elements that are necessary
# ex:
p = line(x, y, source)
# now add 'p' to the doc object
doc.add_root(p)
# define a callback if necessary
# and register that callback
doc.add_periodic_callback(_cb, delay)
- 添加該應用服務器金字塔配置對象的路徑位置。 主要在
__init__.py
或您配置路由的任何其他文件中。
conf.add_route('bokeh_app', '/bokeh-app')
- 添加視圖,其中
bokeh_app
必須被呈現。這個功能可以寫在views.py
或你認爲合適的地方。
from pyramid.view import view_config
from bokeh.embed import server_document
@view_config(route_name='bokeh_app', renderer='static/plot.jinja2')
def bokeh_view(request):
# this '/app' route to the plot is configured in step. 4
# using default host and port of bokeh server.
# But, the host and port can be configured (step. 4)
script = server_document('localhost:5006/app')
# assuming your jinja2 file has
# {{ script|safe }}
# embedded somewhere in the <body> tag
return {'script': script}
- 現在,火了背景虛化服務器。
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.server.server import Server
# bokeh_doc is the function which defines the plot layout (step. 1)
chart_app = Application(FunctionHandler(bokeh_doc))
# the '/app' path is configured to display the 'chart_app' application
# here, a different host and port for Bokeh-server could be defined
# ex: {"<host2:9898>/app_bokeh": chart_app}
bokeh_server = Server({"/app": chart_app}, allow_websocket_origin=["localhost:6543"])
# start the bokeh server and put it in a loop
server.start()
server.io_loop.start()
allow_websocket_origin
發生在必須升級以支持背景虛化需要網絡套接字連接字符串列表。在這種情況下,我們需要給金字塔服務器的URL
- 最後,啓動金字塔服務器
from wsgiref.simple_server import make_server
pyramid_app = conf.make_wsgi_app()
pyramid_server = make_server('localhost', 6543, pyramid_app)
pyramid_server.serve_forever()
我小有一點糊塗 - 也是如此代碼在第4部分中,您啓動Bokeh服務器必須是不同的應用程序並與金字塔應用程序分開運行?我想知道,因爲理想情況下,我會在我的金字塔應用程序中嵌入散景服務器,並讓它在我的金字塔應用程序內啓動Bokeh(即,當我運行'pserve development.ini'之類的東西啓動我的散景服務器時),然後當我進入'散景'頁面時,它已經爲我準備好了。 – hhprogram
不好意思 - 我說這就是我想要做的。但是我想向你確認這聽起來像你的解決方案要求你分別運行散景服務器。然後啓動金字塔服務器 - 是否正確? – hhprogram
可能找到了解決方案。稍後我會更多地閱讀它 – hhprogram