Sharing a document between sessions/tabs

Hi!

First of all, thanks for a great framework – it’s really a pleasure to use.

I have an application that I serve by instantiating a Server and adding it’s show callback to server.io_loop, all that in __main__ of my python file – so I’m not using bokeh serve etc.

It looks something like this:

    class Viewer:
        def __init__(self):
            self.button = widgets.Button(label='Increase')
            self.button.on_click(self.on_click)
            self.val = 0
            self.text = widgets.Div(text=f'{self.val}')
        
        def on_click(self):
            self.val += 1
            self.text.update(text=f'{self.val}')

        def view(self, doc):
            doc.add_root(bokeh.layouts.row(
                self.button,
                self.text
            ))
    
    v = Viewer()
    app = Application(FunctionHandler(v.view))
    server = Server({'/app': app})
    server.start()
    
    server.io_loop.add_callback(server.show, '/')
    server.io_loop.start()

Currently each browser tab creates a new session / doc. Is there a way to share the Document object, similarly to how the panel package does it?

Thanks

It is possible to connect to an existing session, but you would have to know the existing session id and specify it as part of the URL as a bokeh-session-id HTTP request argument. This is not a common thing to do at all. Otherwise, new connections always generate new sessions, and sessions always have their own unique Document.