Google Cloud Platform (GCP)#

First, you need to set up your Google cloud account following the Cloud Run documentation or the App Engine documentation depending on whether you would like to deploy your Panel app to Cloud Run or App Engine.

Next, you will need three files:

  1. This is the Python file that creates the Panel App.

  2. requirements.txt: This file lists all the package dependencies of our Panel app. Here is an example for requirements.txt:

  1. app.yml (for App Engine) or Dockerfile (for Cloud Run)

Here is an example for app.yml (if you would like to deploy to App Engine):

runtime: python
env: flex
entrypoint: panel serve --address --port 8080 --allow-websocket-origin="*"

  python_version: 3

Here is an example for Dockerfile (if you would like to deploy to Cloud Run):

# Use the official lightweight Python image.
FROM python:3.10-slim

# Allow statements and log messages to immediately appear in the Knative logs

# Copy local code to the container image.
COPY . ./

# Install production dependencies.
RUN pip install --no-cache-dir -r requirements.txt

# Run the web service on container startup.
CMD panel serve --address --port 8080 --allow-websocket-origin="*"

Finally, to deploy a Panel app to App Engine run gcloud app create and gcloud app deploy.

Deploying with Cloud Run#

To deploy a Panel app to Cloud Run, run gcloud run deploy.

Panel apps use a websocket to the running Bokeh server. Websockets are considered by Cloud Run to be long-running HTTP requests.

If you deploy a panel app on GCP with Cloud Run, make sure you set up a long request timeout, with CLI parameter --timeout=...

The default timeout is 5 minutes, which makes the panel app lose its websocket connection after this time, leading to unresponsive UI, because Cloud Run considers the websocket as timed-out.

You can extend the timeout up to 60 minutes.

To extend the timeout duration, run gcloud run deploy --timeout 60min.

For detailed information and steps, check out this example on how to deploy a Panel app to App Engine and this example on how to deploy a Panel app to Cloud Run.

Regarding Cloud Run, check out the documentation about Cloud run and WebSockets and about the --timeout option