# Bokeh server embedded in gunicorn/Flask hosted to cloud

**URL:** <https://discourse.bokeh.org/t/bokeh-server-embedded-in-gunicorn-flask-hosted-to-cloud/6199>\
**Category:** Community Support\
**Tags:** server\
**Created:** [August 22, 2020, 4:11pm UTC](https://discourse.bokeh.org/t/bokeh-server-embedded-in-gunicorn-flask-hosted-to-cloud/6199 "2020-08-22T16:11:13Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![\_jm](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/_/ac91a4/32.png) [@\_jm](https://discourse.bokeh.org/u/_jm)\
**Post date:** [August 29, 2020, 11:59am UTC](https://discourse.bokeh.org/t/bokeh-server-embedded-in-gunicorn-flask-hosted-to-cloud/6199/14 "2020-08-29T11:59:13Z")

</div>

For others that have application architectures similar that embed a **bokeh** server in a **gunicorn/Flask** framework and want to deploy it to a platform as a service / cloud service, this can be done in **Heroku** using two _dynos_. After exhaustively exploring different mechanisms and helpful exchanges with the **Heroku** support team, getting everything to work in one _dyno_ is not possible.

**DETAILS**

_Flask-app_ which embeds the bokeh server on one _dyno_:

Create a python Flask app, e.g. a simple one as follows, and use the Heroku Procfile to run it via **gunicorn** , which is well documented on Heroku’s site.

```
from flask import Flask, render_template

from bokeh.client import pull_session
from bokeh.embed import server_session

BOKEH_URL = "https://<bokeh-app-name>.herokuapp.com/<bokeh-server-name>"

app = Flask( __name__ )

@app.route('/', methods=['GET'])
def bkapp_page():
    with pull_session(url=PANEL_URL) as session:
        script = server_session(session_id=session.id, url=BOKEH_URL)
        return render_template("embed.html", script=script, template="Flask")

```

_Bokeh server app_ which runs the bokeh server on second _dyno_:

Implement this as usual and create a Heroku Procfile that runs the server, e.g.

`web: bokeh serve --address="0.0.0.0" --port=$PORT <bokeh-server-name> --allow-websocket-origin=<flask-app-name>.herokuapp.com`

NB: The port argument is important b/c Heroku assigns the port that is used; you cannot choose it yourself.

NB: The quantities in \<…\> above should reflect the app names for your Heroku apps and the name of your bokeh server following the bokeh conventions if it is in single-file or directory format. Caveat, that only the single module `bokeh-server-name.py` case has been tested in determining the viability of the approach.

Thanks to @p-himik and @Bryan for the valuable help getting this to work!

---

_[View the full topic](https://discourse.bokeh.org/t/bokeh-server-embedded-in-gunicorn-flask-hosted-to-cloud/6199)._
