Deployment Tips for Gunicorn

Hi @jamiec

A typical way to use gunicorn with a bokeh server is to leverage Flask to integrate the bokeh server sessions.

You can refer to the flask_gunicorn_embed.py example in the bokeh GitHub repository for details. Seeserver embed (flask_gunicorn_embed.py).

The readme there indicates running with

gunicorn -w 4 flask_gunicorn_embed:app

But, the gunicorn command can also be used as normal with a config file rather than specifying options like the number of workers (–w 4) on the command line.

The panel server is built on top of the bokeh server, so to get things to work under panel, only minimal changes are required. For the above-referenced flask_gunicorn_embed.py example, one way to accomplish this is to implement the following change (i.e. comment out the bokeh doc.add_root() statement and replace with panel layout and server_doc() statements; and obviously include the panel import).

#doc.add_root(column(slider, plot))
_col = pn.Column(slider, plot)
_col.server_doc(doc)

Note: There have been periodic recent regressions in panel that cause layouts to not render properly. See the following panel discourse topic for details.

1 Like