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:
main.py
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")
@app.get("/")
async def read_root():
return {"message": "Success"}
@app.get("/panelapp")
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}
)
def create_app():
app = pn.Row("Hello World from Panel!")
return app.servable()
pn.serve(
{"/app": create_app},
port=5000,
allow_websocket_origin=["127.0.0.1:8000"],
address="127.0.0.1",
show=False,
)
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8000)
Any help would be useful.
Sam