from contextlib import contextmanager
from bokeh.server.server import Server
@contextmanager
def call_server(bkapp):
server = Server({"/": bkapp})
try:
server.start()
yield server
except KeyboardInterrupt:
pass
finally:
pass
def bokeh_app_wrapper(**kwargs):
# setup settings before creating the app here
def bokeh_app(doc):
# now you can use previously defined settings
# add items to `doc`
doc.add_root(...)
return bokeh_app
def app(**kwargs):
# e.g. data handling
return bokeh_app_wrapper(**kwargs)
def main(**kwargs):
with call_server(app(**kwargs)) as app_server:
app_server.io_loop.add_callback(app_server.show, "/")
app_server.io_loop.start()
App layer could be skipped if there is no need to handle anything there.
Start server without
bokeh serve
https://stackoverflow.com/questions/54069272/how-to-run-a-bokeh-server-without-bokeh-server-show-command
e.g. this can be wrapped as
App layer could be skipped if there is no need to handle anything there.