Panel show on same port as running jupyter

I run code in a REPL connected to a jupyter kernel managed by a jupyterlab server running on port 8888. I then visualise various plots with code like the following

import pandas as pd
import hvplot.pandas
import panel
df = pd.DataFrame({"A":[1,2]})
pane = panel.panel(df.hvplot())

The above works well. I can show many such panes on different ports calling, close them all at once with panel.state.kill_all_servers(), and even group many panes on the same port with a dictionary in panel.serve({"this_pane": pane}) … My use is to interact with the data in this REPL as I continue manipulating the data.

I use emacs with emacs-jupyter but my question is applicable in a jupyter notebook or jupyter console. I want to show the apps under the same port as the jupyter server, perhaps under a new slag like https://localhost:8888/myapps/this_pane/. That is, I want to achieve what the panel preview button does in the jupyter notebook, where the same port 8888 is used, or perhaps what jupyter-panel-proxy does where it adds a https://localhost:8888/panel service. But I want to do it using methods available from a console.

If it makes a difference, I am using nb-conda-kernels to launch ipykernels in other conda environments.

The reason I want this is so that I can access the many plots when I run the jupyter server remotely (with one ssh or one docker port forwarding - the one of the jupyter server). The alternative is to have two port forwarding, 8888 for the jupyter server and 8889 for the bokeh server, and call each time I want a new plot to stop the previous one

running_server =
# interact..
# do some more work
running_server =
# want to see the first one again briefly..
running_server =
# continue with next_pane..

There’s a button in Jupyter Lab that allows you to preview panel apps. Not sure if it runs on the same port though.

Yes, the preview button does use the same port! I am looking for a way to use something similar on a REPL console and (in contrast to the preview button? I am not sure) for each manual interactive panel call (rather than a whole document).

This is not the question I am asking, but as a compromise, is there a way to serve from the REPL multiple apps on the same port but not in the same call of panel.serve(d)? I would much prefer to use the same port as jupyter-lab (I might have less control over exposing more ports in the future) but at least this way I could have my workflow for now without stopping each server each time in order to reuse that predefined port.

I found a solution with jupyter-server-proxy. I had seen this extension before but I thought it was only for running live pre-configured servers. By just installing it in the base environment of jupyter-lab, after setting BOKEH_ALLOW_WS_ORIGIN="*", then will launch at a random port say 5321 and can be accessed at


where port 8888 is the one of jupyter-lab.