Does panel have / need a mechanism for using cookies?

I wrote an app recently and deployed it to Heroku. It is nice that it is so easy to do. That said, its behavior is certainly different in a multi-user environment from how it behaves in a notebook. I was being clever to cache some moderately expensive i/o, so that it would only be performed when widget changes require it.

Alas, of course, Heroku does not spin up a new instance for each connection. So this cacheing actually just causes surprising behavior more quickly.

Sorry could you expand a little bit on what exactly you want to do. Set cookies? Read cookies? Create an independent cache for each user session?

Good question. Since the user is not logging in. I guess it is the “hit myself in the head” moment when I realized that Jupyter is single user setup and deploying an app to a multi-user environment are quite different.

Can panel help here?

Sorry, I’m still not clear what you’re asking. Yes, Panel has full support for keeping session state separate for multiple users or sharing state across users. I’ll need more details to give more specific advice on what you should do.

I guess I need to find an example or a doc on how to save/restore state.

I have 2 tabs, each sharing a list selection and a date selection. One additionally has another list selection and a checkbox. See the model, layout and widgets here

Existing version on heroku here Changing the date requires retrieving external data via http. Since most are likely to be happy with the most current snapshot, it probably would be worthwhile not retrieving it each time.

I guess I still don’t see how you’re actually serving the app. If you launch the app with panel serve then each user should get a new session. If you want to cache data across sessions I would use pn.state.cache which is a simple dictionary which will be accessible from all sessions.

1 Like

Does each session have a separate python process? When I open two tabs (both localhost) of the same panel serve app, and run a long calculation in one, the GUI becomes nonresponsive in the other. Is this behavior different with multiple external users?
Or should I be doing long calculations in a different thread/process in the first place?

There are several options:

  1. Offload long-running tasks to threads
  2. Start your server with panel serve ... --num-procs N where you should choose a sensible N
  3. Put your application behind a reverse proxy and load balancer.
2 Likes