Launching Panel App

Hi Everyone,

I am trying to deploy a Panel app within FastAPI (following the documentation here). Things work fine locally while running the command: uvicorn main:app --reload

But since I want to deploy using Docker, I am running into an issue:

The step where the Panel App is served to a local port (say, 5000) blocks the rest of the code (e.g., launching a uvicorn server, etc, which serves the FastAPI app that consumes and renders the Panel App)

Here is a simple example:

import panel as pn
from bokeh.embed import server_document
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
import uvicorn

app = FastAPI()
templates = Jinja2Templates(directory="templates")

async def read_root():
    return {"message": "Success"}

async def bkapp_page(request: Request):
    script = server_document("")
    return templates.TemplateResponse(
        "base.html", {"request": request, "script": script}

def create_app():
    app = pn.Row("Hello World from Panel!")
    return app.servable()

    {"/app": create_app},

if __name__ == "__main__":, host="", port=8000)

Any help would be useful.


1 Like

Maybe adding the argument ‘threaded=True” to pn.serve would be a possibility and help?

Thanks very much. This at least works to the extent that the base end point works, so the function is deployed.

The problem though is that the local panel server cannot be accessed when accessed by me outside the machine:

As you see, the text above the app in the HTML page is rendering well, but not the script that was to be placed there by the bokeh server_document.

Maybe it is a naive question, but would be glad to get some right direction to resolve this.

Best regards and thanks once again,

Do you or others have any comments on this? I am trying to deploy an AWS lambda function with this small app for testing.