为了复杂,使用金字塔,我可以创建静态散景图,然后使用div here等div标签对它们进行合并。
Bokeh documentations清楚地解释了如何为交互式数据探索设置散景服务器,并且我已成功创建了这样的应用程序。
我想做的是在金字塔视图页面中有一个交互式图形。本页面的要求如下:
有些事我不清楚:
有one paragraph提及散景服务器如何嵌入Flask或Tornado应用程序中。但这段话对我来说太简短了,现在没有意义。所以我在问金字塔怎么做?
答案 0 :(得分:3)
正如bigreddot所说,工作流程与代码中的微小变化非常相似。我实际上根据他的答案建立了我的答案。谢谢bigreddot!
以下是我将bokeh-sever与Pyramid集成的解决方案。
General
1) "before each" hook
0 passing (10s)
1 failing
1) "before each" hook:
Uncaught NetworkingError: Cannot read property 'replace' of undefined
at findTargetPort (node_modules/zombie/lib/reroute.js:50:28)
at Socket.Net.Socket.connect (node_modules/zombie/lib/reroute.js:69:18)
at Agent.connect [as createConnection] (net.js:106:35)
at Agent.createSocket (_http_agent.js:217:26)
at Agent.addRequest (_http_agent.js:187:10)
at new ClientRequest (_http_client.js:272:16)
at Object.request (http.js:39:10)
at features.constructor.handleRequest (node_modules/aws-sdk/lib/http/node.js:42:23)
at executeSend (node_modules/aws-sdk/lib/event_listeners.js:304:29)
at Request.SEND (node_modules/aws-sdk/lib/event_listeners.js:318:9)
at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:101:18)
at Request.emit (node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (node_modules/aws-sdk/lib/state_machine.js:14:12)
at node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:115:18)
at callNextListener (node_modules/aws-sdk/lib/sequential_executor.js:95:12)
at node_modules/aws-sdk/lib/event_listeners.js:220:9
at finish (node_modules/aws-sdk/lib/config.js:315:7)
at node_modules/aws-sdk/lib/config.js:333:9
at Credentials.get (node_modules/aws-sdk/lib/credentials.js:126:7)
at getAsyncCredentials (node_modules/aws-sdk/lib/config.js:327:24)
at Config.getCredentials (node_modules/aws-sdk/lib/config.js:347:9)
at Request.SIGN (node_modules/aws-sdk/lib/event_listeners.js:192:22)
at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:101:18)
at Request.emit (node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (node_modules/aws-sdk/lib/state_machine.js:14:12)
at node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:115:18)
at Timeout.callNextListener [as _onTimeout] (node_modules/aws-sdk/lib/sequential_executor.js:95:12)
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()
接收必须升级的字符串列表,以支持散景所需的Web套接字连接。在这种情况下,我们需要提供金字塔服务器的URL
allow_websocket_origin
答案 1 :(得分:2)
在所有情况下,嵌入另一个(烧瓶,django,龙卷风等)过程的运行公式基本相同。他在这个“独立”示例中展示了基本要素,该示例仅显示了您自己管理的龙卷风IOloop
上启动Bokeh服务器所需的步骤:
https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/standalone_embed.py
基本步骤是:
创建一个生成Bokeh文档的函数:
def modify_doc(doc):
# setup up plots and widgets in a layout, then
doc.add_root(some_layout)
使用此功能创建一个散景Application
,并使用它启动一个散景服务器:
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.server.server import Server
bokeh_app = Application(FunctionHandler(modify_doc))
server = Server({'/': bokeh_app}, io_loop=io_loop)
server.start()
最后,将Bokeh Server
添加到您创建和管理的龙卷风IOloop
中:
from tornado.ioloop import IOLoop
io_loop = IOLoop.current()
io_loop.add_callback(server.show, "/")
io_loop.start()
然后您的(Flask,Django,Pyramid,无论如何)视图可以使用<iframes>
或bokeh.embed.autoload_server
以标准方式从此服务器嵌入Bokeh应用程序(例如,参见Flask嵌入脚本)