Serving a bokeh application within django: How to freely place individual components?

we are just getting started with bokeh, in our current project we want to serve bokeh content in a django project. Our docker-compose dev environment has the following components

  • gunicorn for django
  • bokeh serve in directory mode
  • nginx to route to gunicorn and bokeh server
  • postgres

We created a bokeh application that we can embed into our django content via ‘server_document’, callbacks and everything works just fine. Now we want to be able to move the components of the application more freely in the django templates: Essentially we want to specify the layout via django and not bokeh anymore. How can we serve the individual components (e.g. a map and a dropdown) while keeping the interactions working? We considered using ‘json_item’ to create individual items both for the map and the dropdowns, but how could we make sure interactions continue to work? Placement would work as we want in this case, as we can specify the div .

TL;DR: What’s the best way to embed different bokeh components into django templates, while being flexible about the placement and keeping interactions working?

Thank you,

I think there is an opened feature request for this

I am trying to do it in flask, but i was not able yet.

Thanks. Is there an alternative to achieve wat we want? From the documentation it sounds like ‘server_document’ is the only way to embed a bokeh app. Should we instead build individual components and then somehow connect them together? Again the example of a dropdown that updates a map. What would be the best way to achieve this?

How is Django started by uwsgi + nginx + asgi? My configuration is finished and bokeh is not available

I think this is unrelated and you might want to open another thread. The way I did it is by running django via gunicorn and bokeh via ‘bokeh serve’ and then use nginx to forward /bokehproxy/ to the bokeh server. Then I used server_document to create the script and pass it to the django template:

doc = server_document(     

Extract from nginx.conf:

location /bokehproxy/ {
    proxy_pass http://bokeh:8050/;