Emulate command line "panel serve" with multiple notebooks using pn.serve()

Hi

I’m trying to emulate the command line

panel serve nb1.ipynb nb2.ipynb nb3.ipynb ...

using pn.serve() so users don’t share state.

I’m thinking of something like this:

# as a main.ipynb perhaps?
from pathlib import Path
from functools import partial
import panel as pn

nb_dir = Path("/app/notebooks/")
nb_dir = Path("/home/blair/projects/notebooks/Jupyter/QuantPanel")

def page_to_panel(pth):
    """Somehow convert a path to a Panel app"""
    print(pth)

ROUTES = {nb.stem: partial(page_to_panel, nb) for nb in nb_dir.glob("*.ipynb") if nb.stem != "main" }

pn.serve(ROUTES, port=5007)

to somehow convert my file paths to Panel objects. It’s not clear how to do this part. I suspect it’s possible as the serve command must do this partially already.

I’ve read the following useful comment among many others and also searched the docs.

Any pointers greatly appreciated and thanks in advance.