Flask/Django 服务器和散景服务器

Flask/Django Server and Bokeh Server

我想用 Python 3.x 实现一个基于 Web 的动态仪表板(就像 R 的 Shiny)

根据我在 YouTube 上阅读和看到的内容,Bokeh 似乎很有希望。

我不清楚何时何地需要 Bokeh 服务器和 Flask/Django 服务器?他们会互补吗?或者我可以在任何一个上工作?他们会提供同样的服务吗?

Bokeh 服务器基于 Tornado which is itself a capable Python web framework and asynchronous networking library. Depending on your needs, it may be possible to simply write a Bokeh app, have it show everything you want, in the way you want. Bokeh exposes some capability to customize app appearance via Jinja2 templates. You can see an example of this in the Gapminder Demo on http://demo.bokeh.org

但是,您可能有更复杂的需求,尤其是在身份验证和访问方面,或者您有需要集成到的现有站点。在这种情况下,您可能正在考虑将 Bokeh 应用程序嵌入到另一个页面中,该页面可能由 Flask、Django、IIS 或其他任何服务提供。有两种基本方法可以做到这一点:

  • 使用 server_document 生成一个 <script> 标签,您可以将其模板化到您的页面中,这会将来自 Bokeh 服务器的应用嵌入到页面中
  • 使用 <iframe> 将来自 Bokeh 服务器的 URL 嵌入页面

这些都可以正常工作。根据您的部署环境的复杂程度,可能需要做更多 "devops-y" 类型的事情来使用代理后面的 Bokeh 服务器或负载均衡器等。Running a Bokeh Server section of the User's Guide 有更多信息用于任何需要深入了解这些细节的人。

如果您要将来自 Bokeh 服务器的应用程序嵌入到另一个网页中,Bokeh 服务器确实需要启动并 运行 为该应用程序提供服务!如何完成这个是一个单独的问题,有几种方法可以做到:

  • 作为外部进程启动,并使用类似 supervisord 的方式进行管理。您可以在 https://github.com/bokeh/demo.bokeh.org

  • 看到完整的示例部署
  • 通过启动您自己的 Tornado IOLoop,在您的 Flask/Django/whatever 应用程序中嵌入 Bokeh 服务器 "inside"。您可以在 examples/howto/server_embed 中看到此技术的一个示例。另外,这应该算是神仙高级用法了。