Panel with FastAPI

I’m trying to embed a simple Panel app with a template in FastAPI. When I browse to http://127.0.0.1:8000, the Panel template does not render for some reason. However it does render perfectly well when I browse directly to http://127.0.0.1:5000/app. Can someone help me figure out what the issue is?

The code:


def createApp():
    x = [1, 2, 3, 4, 5]
    y = [6, 7, 2, 4, 5]
    p = figure(title="Simple line example", x_axis_label="x", y_axis_label="y")
    p.line(x, y, legend_label="Temp.", line_width=2)

    template = pn.template.FastListTemplate(title="My FastListTemplate")
    template.main.append(pn.Row(p))
    template.servable()
    return(template)

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

@app.get("/")
async def bkapp_page(request: Request):
    script = server_document('http://127.0.0.1:5000/app')
    return templates.TemplateResponse("base.html", {"request": request, "script": script})

pn.serve({'/app': createApp},
        port=5000, allow_websocket_origin=["127.0.0.1:8000"],
        address="127.0.0.1", show=False)
1 Like

Maybe try 0.0.0.0; not sure.