/g4g24-ee-python-app

Primary LanguageJupyter NotebookApache License 2.0Apache-2.0

g4g24-ee-python-app

Open in Cloud Shell

Develop EE Python dashboard app

Open notebooks/notebooks/ee-voila-app.ipynb for an example showing to develop EE-enabled dashboard using Python and ipywidgets.

Make sure to replace the YOUR_PROJECT_NAME with your Cloud Project name where Earth Engine is registered. If this not the case - follow the https://code.earthengine.google.com/register and register your project first.

Run Voila locally during development

For local development, it is best to run voila in a separate virtual environment. Create a Python virtual environment and install dependencies in the following way:

cd ./cloudshell_open/g4g24-ee-python-app
pip3 install virtualenv
virtualenv venv
source venv/bin/activate
pip3 install -r requirements.txt 

The following command will start a new voila server in the Cloud Shell which can be used for testing during development:

voila --Voila.tornado_settings="{'allow_origin': '*'}" ./notebooks/ee-voila-app.ipynb

Notice that we disable CORS to make sure that the app URL redirected by the Cloud Shell can be accessed.

After you run the above command in the Cloud Shell Terminal, it will print the URL of the server started on the Cloud Shell machine http://localhost:8866/ and will automatically redirect all traffict to the viola server, follow that link:

image

If everything works fine, you should page like this:

image

Deploy to Cloud run

Edit deploy.sh and replace the YOUR_PROJECT_NAME in the second line of the script, then run ./deploy.sh to deploy your app to Cloud Run.

Troubleshouting

If image build fails, test docker image locally by calling:

docker pull us-central1-docker.pkg.dev/dgena-demo2/g4g24-repository/ee-python-app:latest
docker images # check image name
docker run -it <IMAGE_NAME> /bin/bash
docker image rm <IMAGE_NAME>

If you get error during deployment - check the Cloud Run Log messages via Cloud Console. Potentially, some roles/permissions will need to be added via Google Cloud IAM to fix it if this happens.