Panel loading issues when trying to deploy Panel with FastAPI on Render

Heya! My team is trying to deploy multiple Panel widgets within a FastAPI application. So far, we followed the instructions about deploying with FastAPI, but we’re having trouble getting everything loading properly on our hosting platform Render.

You can check out the code here: GitHub - technologiestiftung/innovationserhebung: Visualizing 10 years of data about innovation in Berlin and Germany (the file is in the /app directory)

When running the project locally, everything renders correctly.

Then, on Render we’re running this command to start the server (with PORT being 8000):

cd app/; uvicorn main:app --host --port $PORT

… but when accessing the page, the panel widgets can’t be loaded (403 error when trying to load their JS files). If I allow all origins via something like allow_websocket_origin=[""], inside pn.serve(), the widgets’ JS can be loaded, but they will immediately lose their web socket connection and not properly load either. This error would be shown:

[bokeh] Failed to load Bokeh session d0Zknpdyni02egdKY6OkIy72OwZeyubBTAQkaa6wSzPo: Error: Lost websocket connection, 1006 ()

I suspect it’s a configuration issue, maybe something around the allow_websocket_origin parameter of pn.serve(), but I cannot find a configuration that works.

Can anyone give me a hint of what might fix the issue? Any support is greatly appreciated!

Hi @herrherrmann-tsb

I have not tried deploying as you do. My guess is that it has something to do with the fact that the Panel server and websocket is available on port 5000.

Render assumes your whole application is available on port 8000 and probably only opens that port. Try contacting render to ask them how to support a use case like this. Or search their community discourse. I can see there are some discussions around support for multiple ports Exposing multiple ports - General - Render.

You can try to see if you can deploy the panel app standalone. Then in the FastApp remove the pn.serve as the panel app is served externally. And then in the server_document point to the place where the panel app is hosted. You might have to also set some Panel prefix argument similar to --prefix the prefix flag to get it working.

1 Like

Thanks a lot for the help, @Marc!

We managed to get our project running with some extra code that manages the ports and web sockets now. Feel free to check the repository if you’re interested.

This topic can be closed now. :saluting_face: