按照复杂性的顺序,对于金字塔,我可以创建静态bokeh图,然后用div标记(如概述的这里 )将它们不相关联。
Bokeh文档清楚地解释了如何设置一个bokeh服务器进行交互式数据探索,我已经成功地创建了这样一个应用程序。
不过,我想做的是在金字塔视图页面中有一个交互式的图形。本页的要求如下:
有些事情我不清楚:
一段提到了如何将bokeh服务器嵌入到一个烧瓶或龙卷风应用程序中。但这一段太短了,我现在无法理解。所以我在问我如何在金字塔中做到这一点?
发布于 2017-10-12 18:50:57
正如双点所说,工作流与代码中的微小变化非常相似。我实际上是根据他的回答来回答的。谢谢双点!
以下是我的解决方案,把波克-塞弗和金字塔.
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接受必须升级以支持bokeh所需的web套接字连接的字符串列表。在这种情况下,我们需要给出金字塔服务器的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()发布于 2017-06-15 14:30:23
嵌入在另一个(瓶、django、龙卷风等)中的运行公式。在所有情况下,流程基本上是相同的。他在这个“独立”示例中给出了基本要素,该示例仅显示了在“旋风”IOloop上启动Bokeh服务器所需的步骤,您可以自己管理:
基本步骤是:
Application,并使用它启动一个Bokeh服务器:
从bokeh.application.handlers导入FunctionHandler从bokeh.application导入应用程序从bokeh.server.server导入服务器=应用程序(FunctionHandler(Modify_doc))服务器=服务器({‘/’:bokeh_app},io_loop=io_loop) server.start()Server添加到您创建和管理的龙卷风IOloop中:
从tornado.ioloop import IOLoop io_loop = IOLoop.current() io_loop.add_callback(server.show,"/") io_loop.start()然后,您的(酒瓶、Django、金字塔等)视图可以使用标准方式使用<iframes>或bokeh.embed.autoload_server从该服务器嵌入Bokeh应用程序(例如,请参阅Flask脚本中的示例)
https://stackoverflow.com/questions/44400581
复制相似问题