arviz-devs / arviz_dashboard

Bayesian Dashboard built on top of Panel
Apache License 2.0
5 stars 2 forks source link

Bokeh server basics #3

Open ahartikainen opened 2 years ago

ahartikainen commented 2 years ago

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

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.

ahartikainen commented 2 years ago

bokeh_app then would contain all the bokeh creation and linking e.g.