Hello Everyone!
I’ve followed the example from Embed Panel in fastApi and have a pretty neat panel app running as part of my broader FastAPI implementation, the one issue I am having is that it all seems to be one app instance running.
e.g. if I capture user inputs to update a parameter, that parameter change persists for a second user connecting to the same app, rather than a separate instance starting up for the new user.
I suspect this relates to the way @t-houssian set stuff up in his (fantastic!) example:
@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)
I read the flask example from here: Deploying Bokeh Apps — HoloViews v1.18.1
… and it seems like maybe I need to leverage pull_session from bokeh.client and server_session from bokeh.embed?
I tried something like this:
@app.get("/")
async def bokeh_app_page(request: Request):
panel_url = f'http://{local_ip}:5000/app'
with pull_session(panel_url) as session:
script = server_session(session_id=session.id,url=panel_url)
return templates.TemplateResponse("base.html", {"request": request,"script":script})
main_app = createApp()
panel_app = pn.serve({'/app': main_app.gspec},
port=5000, address=f"{local_ip}",allow_websocket_origin=[f"{local_ip}:8000",], show=False)
but now when I try to run my app, I get the following error:
…\lib\asyncio\base_events.py", line 526, in _check_runnung
‘Cannot run the event loop while another loop is running’)
RuntimeError: Cannot run the event loop while another loop is running
Am I on the right track? Any advice from others who are running the panel server in parallel with another framework like fastapi?