How do I write code that allows different session to have different states?
Currently, all my sessions are sychronized / share their states without explicitly coding it that way.
A minimum example:
import panel as pn
pn.extension()
dashboard = pn.Column('# Dashboard',
pn.Tabs(pn.Spacer(), pn.Spacer(), pn.Spacer())
)
server = pn.serve(dashboard, start=True, show=True)
If I now open multiple sessions, even across clients (so different IPs), once I click a tab in one session, all other sessions switch the tab as well.
How do I get to a situation where sessions behave independently?
Adding a subtle point to this topic that I learned the hard way. Regardless of servable(), if using parameterized classes as parameters, you should initialize them in the init and not in the parameter declaration if you want them to be session-independent.
import param
import panel as pn
class SomeParameter(param.Parameterized):
data = param.DataFrame()
class SomeClass1(param.Parameterized):
# Initializing SomeParameter at class level will make param1 shared across all sessions
param1 = param.Parameter(SomeParameter())
class SomeClass2(param.Parameterized):
param1 = param.Parameter()
def __init__(self, **params):
# This will make param1 session independent
param1 = SomeParameter()
super().__init__(**params)