Panel app with independent sessions

Hi,

I have an App that uses the BootstrapTemplate and I would like to make sure that multiple users can run concurrent sessions, i.e. their session should be independent from each other.
I know that similar topics have been already discussed, but even though I have been screening the web for a solution, I could not find it yet.

The below is a minimal example of my app.
When running it and opening two sessions (e.g. on different browsers), I can see that both react together, e.g. if I change the selected color in one, the other one will update synchroneously.
Is there a way to update the below code to have two independent sessions?

Many thanks already.

import panel as pn
import pandas as pd

class MainApp:
    
    def __init__(self):
        self.tabs_mapping = {
            'Tab1': self.create_tab1(),
            'Tab2': self.create_tab2()
        }

        # Tab Button 1
        self.tab1_button = pn.widgets.Button(
            name='Tab1', button_type='warning', icon='file-info', styles={'width': '100%'}
        )
        self.tab1_button.on_click(lambda event: self.display_tab('Tab1'))

        # Tab Button 2
        self.tab2_button = pn.widgets.Button(
            name='Tab2', button_type='warning', icon='file-info', styles={'width': '100%'}
        )
        self.tab2_button.on_click(lambda event: self.display_tab('Tab2'))

        # Current tab and sidebar
        self.current_tab = pn.Column(self.tabs_mapping['Tab1'], styles={'width': '100%'})
        self.sidebar = pn.Column(
            pn.pane.Markdown('TABS'), self.tab1_button, self.tab2_button,
            styles={'width': '100%', 'padding': '30px'}
        )

        # Wrapping into Holoviz BootstrapTemplate
        pn.extension('plotly', notifications=True)
        self.template = pn.template.BootstrapTemplate(
            title='Board',
            sidebar=[self.sidebar],
            main=[self.current_tab],
            header_background='black',
            site='ADR',
            theme=pn.template.DarkTheme,
            sidebar_width=250,
            busy_indicator=None,
        )

    def display_tab(self, tab_key):
        self.current_tab.clear()
        self.current_tab.append(self.tabs_mapping[tab_key])

    def create_tab1(self):
        ### Add box to enter the ticker, the expiry, etc.
        self.color_select = pn.widgets.Select(
            name='Select Color', options=['Black', 'White'], width=175
        )
        self.form_select = pn.widgets.Select(
            name='Select Form', options=['Circle', 'Cube'], width=175
        )

        return pn.Column(
            pn.Spacer(height=25),
            pn.Row(
                pn.Spacer(width=25), self.color_select, pn.Spacer(width=15), self.form_select
            )
        )

    def create_tab2(self):
        return pn.Column('No Functionality in this tab!')

    def view(self):
        return self.template


if __name__ == '__main__':
    app_title = 'MainApp'
    app_routes = {'MainApp': MainApp().view}
    pn.serve(
        app_routes,
        address='0.0.0.0',
        port=5000,
        websocket_origin='*',
        show=True,
        start=True,
        verbose=True,
        title=app_title
    )

...
def main_view(): 
  return MainApp().view()
...
app_routes = {'MainApp': main_view}
...

See Serving multiple applications — Panel v1.7.1

Sorry, I noticed a typo in my solution and fixed it now.

The reason your original code is synchronizing across sesstions because it is sharing the same object even though you are assigning a function to the app_routes, the function is returning the same view object (template). My only change is to create a new MainApp object on each call of main_view function.

This works indeed fine.
Many thanks for the swift response and help!