Dash app with jupyter-server-proxy

I want to deploy a Dash/Plotly application on Renkulab using jupyter-server-proxy similar to the streamlit example described here: How to deploy Streamlit in renku

This is my approach so far:

1) Create a new environment in .renku/renku-ini:

[renku "interactive"]
default_url = /dash
lfs_auto_fetch = true

2) Define the jupyter_notebook_config.py:

c.ServerProxy.servers = {
    'dash': {
        'command': [
            'python',
            'app.py',
        ],
        'port': 5000,
    }
}
  1. Add the following requirements:
dash
jupyter-server-proxy
jupyter-dash
  1. The actual app is defined in appy.py like this:
from jupyter_dash import JupyterDash
JupyterDash.infer_jupyter_proxy_config()
app = JupyterDash(__name__)

(details are defined here...)

if __name__ == "__main__":
    app.run_server(mode="jupyterlab", debug=False, port=5000, host='0.0.0.0')

If I call the python script locally it works. However, in Renkulab I receive the following error when starting the session:

Any ideas what could be missing? I also tried a version using gunicorn instead of calling the python script directly (this is for example required when deploying the app on Heroku) with the same result.

Thanks in advance!

Hey @manuelknott can you share a link to the project? If the one where this has been tried contains information you don’t want to share, you can make another one just for testing this.

I created a public minimal example here:

Hi Manuel, thanks for setting up the example project! Looking at the logs, it seems that the port configuration is wrong?

2022-06-02T13:07:00.648104731Z Dash is running on http://127.0.0.1:8050/
2022-06-02T13:07:00.648150454Z 
2022-06-02T13:07:00.648713674Z  * Serving Flask app 'app' (lazy loading)

In your jupyter config you have

c.ServerProxy.servers = {
    'dash': {           # the name of the environment
        'command': [
            'python',
            'app.py'
        ],
        'port': 5000
    }
}

so if you change the port to 8050 it should work. I’ve tried that in my fork and the app starts but all I see is “Loading…”:

Hi Rok,

thanks for pointing out the mismatching ports. I fixed it in the current commit of the minimal example.

However, the “Loading…” issue still remains, and I dug deeper into it:

The main issue is that jupyter_dash works like a charm when being called from a jupyter notebook environment, as this is the library’s main purpose. It does not work when being called from a python file since it is dependent on the jupyter_dash frontend extension.

I tried a couple of things:

  • Calling a notebook with papermill or nbconvert does not work as the jupyter extensions are not used.
  • Calling the python script with “jupyter run …” does not work (same issue)
  • I also tried to not use the above mentioned dependencies but to serve the plain flask app (see the “no_jupyterdash” branch in the example’s repo) → no success so far

There is also a related github issue here.
I tried adding requests_pathname_prefix='/proxy/8050/' to the JupyterDash constructor.
The logs show that the app is running at {host}:8888/proxy/8050, but it is still stuck in the “loading…” phase.

I ran out of ideas at this point.

When opening the “lab” environment with my image, I receive a popup that the lab extension “jupyterlab-dash” is missing. Not sure if that would solve anything. Would maybe be worth a try to add it to the Renku Image.