Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask/Django Server and Bokeh Server

Tags:

python

bokeh

I want to implement a dynamic web based dash board with Python 3.x (Like Shiny for R)

Bokeh seems promising from what I have read and seen in YouTube.

What isn’t clear is when and where will I need a Bokeh server and a Flask/Django Server? Will they complement each other? Or I can work on either one? Will they both be serving the same thing?

like image 790
Harsh Goyal Avatar asked Dec 20 '16 08:12

Harsh Goyal


1 Answers

The Bokeh server is based on 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.

However, you may have more sophisticated needs, especially around authentication and access, or have an existing site that you need to integrate into. In this case, you are probably looking at embedding a Bokeh app in another page, which might be served from Flask, or Django, or IIS, or whatever. There are two basic ways to do this:

  • using server_document to generate a <script> tag that you can template into your page, which will embed an app from a Bokeh server into the page
  • using <iframe> to embed a URL from a Bokeh server into the page

Either of these can work just fine. Depending on the sophistication of your deployment environment, there may be more "devops-y" type things to do to use a Bokeh server behind a proxy or with a load balancer, etc. The Running a Bokeh Server section of the User's Guide has a lot more information for anyone needing to dive into those details.

If you are embedding an app from a Bokeh server into another web page, the Bokeh server does need to be up and running to serve the app! How to accomplish this is a separate concern, there are a few ways you might do it:

  • start up as an external process, and manage with something like supervisord. You can see a full example deployment like this at https://github.com/bokeh/demo.bokeh.org

  • embed a Bokeh server "inside" your Flask/Django/whatever app by starting your own Tornado IOLoop. You can see one example of this technique in examples/howto/server_embed. Also, this should probably be considered fairy advanced usage.

like image 96
bigreddot Avatar answered Oct 02 '22 15:10

bigreddot