Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bokeh server basics #3

Open
ahartikainen opened this issue Jun 13, 2022 · 1 comment
Open

Bokeh server basics #3

ahartikainen opened this issue Jun 13, 2022 · 1 comment

Comments

@ahartikainen
Copy link
Contributor

ahartikainen commented Jun 13, 2022

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant