Managing pull_session and server_session from FastAPI

@Hoxbro , great example, and it’s helped me set up some login stuff (which was also an issue I had on my to-do list). My original question however, was more related to the bokeh document sessions? (not sure if I am using the right term)

The issue I am running into is that if I have 2 users on the site at same time, they seem to be accessing the same underlying bokeh/panel document… if user 1 changes a pn.widgets.CheckButtonGroup value, for example, user 2’s browser reflects that selection too… they aren’t independent sessions!

I figured that panel/bokeh would instantiate a new class instance for each connection, but that doesn’t seem to be the case.

I updated parts of my code to reflect how used the server_session function in your repo example:

 script = server_session(
        session_id=generate_session_id(SECRET_KEY, signed=True), url=url
    )

…and updated my pn.serve section as well:

pn.serve(
    serving,
    port=5006,
    allow_websocket_origin=ALLOWED_HOSTS,
    address=f"{local_ip}",
    show=False,
    sign_sessions=True,
    secret_key=SECRET_KEY,
    generate_session_ids=False,
    num_process= 2,
)

…but I am still seeing the same behaviour (linked plots between 2 users).

How do I get two separate instances of the same app class? Do I need to launch a separate pn.serve() on a different port for each?

It sounds kind of similar to what @khannaum was describing in October:

Looks like maybe @t-houssian had a solution using param.ObjectSelector instead of pn.widgets that I haven’t quite wrapped my head around… I think I need to go back and read through the panel docs again; feel like I am missing something fundamental in the way it works… I thought each connection would create a new server document based on …
https://panel.holoviz.org/user_guide/Server_Deployment.html

Whenever a user accesses the app or dashboard in a browser a new session is created which executes the app code and creates a new Document containing the models served to the browser where they are rendered by BokehJS.