Force to open a new browser window with standalone bokeh server

I want to run python app.py and hope it opens a new browser window no matter whether a browser is already open or not. How to achieve this? Thanks!

Minium working example:

app.py

from bokeh.server.server import Server
from bokeh.models import TextInput


def make_document(doc):
    status_text = TextInput(title='', value='Ready', disabled=True,
                                     sizing_mode='stretch_width')
    doc.add_root(status_text, sizing_mode='stretch_width')


apps = {'/': make_document}
server = Server(apps)
server.start()
server.io_loop.add_callback(server.show, "/")
server.io_loop.start()

Per the documentation you could try passing new="window" to open a new window every time (e.g. use functools.partial or lambda to bake in the different param value and pass the wrapper to add_callback).

However, please be advised that Server.show is really just a very thin wrapper on top of the Python stdlib webbrowser.open function. That function has a lot of platform-dependent, 'if possible", caveats. There is no guarantee that that what you ask for is possible on all platforms, or on the platform you happen to be using. YMMV and you will just have to try and see.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.