How to customize the display URL from panel serve for use behind JupyterHub with jupyter-server-proxy

With this sample code

import panel as pn
srv = pn.panel(
    pn.widgets.FloatInput(name='an input one')
).show(port=5007)

we get

Launching server at http://localhost:5007

Given our deployment is behind JupyterHub with jupyter-server-proxy installed, we would want to have this format of display URL instead: https://OUR_HOST/jupyter/user/OUR_USER/port/5007/.

Does Panel allow customizing the display URL via environment variable containing a template string?

For example Dask dashboard has DASK_DISTRIBUTED__DASHBOARD__LINK="/user/{JUPYTERHUB_USER}/proxy/{port}/status", see mention how to proxy dashbord link in README · Issue #183 · dask/dask-labextension · GitHub.

With that DASK_DISTRIBUTED__DASHBOARD__LINK env var set, the Dask client displays the dashboard URL nicely when behind JupyterHub. User do not have to manually alter the URL, less error-prone and more user-friendly.

With DASK_DISTRIBUTED__DASHBOARD__LINK env var:

Hi @tlvu

Instead of show you should use servable.

Then use panel serve with —port, —address (or host?) and —prefix.

Try using panel serve —help to see the available flags.

I believe the flags can be replaced by environment variables.

Hi @Marc

We would prefer to avoid using the CLI panel serve since our users are inside JupyterLab environment.

We have tried it in the past actually and we ended up needing 3 notebooks to coordinate everything, too much for our users.

And we also do not want our users to know anything about the specific configurations.

The trick from Dask dashboard link is the cleanest. Users do not change anything to their workflow. It just magically display the proper URL behind the proxy to the users.

I think I need more context here.

We are also using a Jupyter hub with the jupyter-server-proxy but we start panel either by

  • using Jupyter panel preview (green icon)
  • using panel serve from terminal

(Both of the above options are not for sharing the app)

(Both of the above options are for sharing the app with other users)

We have not yet used panel-server-proxy, but would probably one day as that would enable us to have all .py and .ipynb files in one or more folders automatically served as panel apps. GitHub - holoviz/jupyter-panel-proxy: Jupyter Server Proxy for Panel

Hi @Marc

Here is a reproducible runtime from Binder you can try: Binder

If you open notebook TEST-panel-servable.ipynb and you click on “using Jupyter panel preview (green icon)”, it does not work.

However, I just managed to get the Panel launcher (from jupyter-panel-proxy) to work for the same notebook TEST-panel-servable.ipynb, had to set environment variable BOKEH_ALLOW_WS_ORIGIN="*" in the Dockerfile.

But the Panel launcher do not recurse to the subdir1 and subdir1/subdir2, so this is half working for us.

The best would be for the “using Jupyter panel preview (green icon)” to work.

1 Like

Hi @tlvu

I tried to take a look. Its a bit hard to dive into because you are using a custom Dockerfile. And python is not available in the terminal.

image

What you could try was setting the environment variable in the dockerfile.

BOKEH_ALLOW_WS_ORIGIN="*"

and also adding the command

jupyter serverextension enable panel.io.jupyter_server_extension

from HoloViz Blog to your dockerfile or a postBuild file like I have here panel-highcharts/postBuild at main · MarcSkovMadsen/panel-highcharts (github.com).

I made a feature request Make debugging of Jupyter Panel Preview easier · Issue #3440 · holoviz/panel (github.com)

1 Like

Hi @Marc,

Python is there, you needed to start bash, then conda init bash, then conda activate birdy, then panel serve TEST-panel-servable.ipynb will work.

I already set

BOKEH_ALLOW_WS_ORIGIN="*"

and

jupyter serverextension enable panel.io.jupyter_server_extension

in the docker image.

I think it could be verified with

jupyter serverextension list

1 Like
$ jupyter serverextension list
config dir: /opt/conda/envs/birdy/etc/jupyter
    dask_labextension  enabled 
    - Validating...
      dask_labextension 5.2.0 OK
    jupyter_archive  enabled 
    - Validating...
      jupyter_archive 3.3.1 OK
    jupyter_server_proxy  enabled 
    - Validating...
      jupyter_server_proxy  OK
    jupyter_resource_usage  enabled 
    - Validating...
      jupyter_resource_usage  OK
    jupyterlab  enabled 
    - Validating...
      jupyterlab 3.3.3 OK
    jupyterlab_git  enabled 
    - Validating...
      jupyterlab_git 0.36.0 OK
    jupytext  enabled 
    - Validating...
      jupytext 1.13.8 OK
    mamba_gator  enabled 
    - Validating...
      mamba_gator 5.1.2 OK
    nbdime  enabled 
    - Validating...
      nbdime 3.1.1 OK
    nbresuse  enabled 
    - Validating...
      nbresuse  OK
    voila.server_extension  enabled 
    - Validating...
      voila.server_extension  OK
    voila  enabled 
    - Validating...
      voila 0.3.5 OK
    panel.io.jupyter_server_extension  enabled 
    - Validating...
      panel.io.jupyter_server_extension  OK
1 Like