Jainabhi
Jainabhi

Reputation: 57

How to run a bokeh server without 'bokeh server --show' command?

I want to run a bokeh interactive application without using "bokeh serve --show" command. Instead, I want to use 'python script_name.py' syntax. Is there any way to do this?

Upvotes: 2

Views: 3394

Answers (2)

WizardOfRobots
WizardOfRobots

Reputation: 56

bigreddot is correct, but the commands given there won't start a bokeh server by itself; you'll need an existing Tornado server running; so here's a standalone solution given in bokeh's docs in the same section:-

Here's the relevant section that starts the server. For the complete example refer to the example code from bokeh's documentation

server = Server({'/': bkapp}, num_procs=4)
server.start()

if __name__ == '__main__':
    print('Opening Bokeh application on http://localhost:5006/')

    server.io_loop.add_callback(server.show, "/")
    server.io_loop.start()

Upvotes: 2

bigreddot
bigreddot

Reputation: 34618

This is covered in the project documentation:

https://docs.bokeh.org/en/latest/docs/user_guide/server.html#embedding-bokeh-server-as-a-library

from bokeh.server.server import Server

server = Server(
    bokeh_applications,  # list of Bokeh applications
    io_loop=loop,        # Tornado IOLoop
    **server_kwargs      # port, num_procs, etc.
)

# start timers and services and immediately return
server.start()

Upvotes: 1

Related Questions