Embedded bokeh server

Any plans to wrap a nice way to embed a bokeh server in an app? I’d like to use it as a single-user dashboard for some apps I’m writing.

I’m looking for a programmatic way to start up a bokeh server and serve a ‘static’ (but not really, because it’s updating via callbacks) plot or three.

I tried doing:

def bokeh_serve(doc, **server_kwargs):

from bokeh.server.server import Server

from bokeh.application import Application

from bokeh.application.handlers import FunctionHandler

applications = { ‘/’ : Application(FunctionHandler(lambda x: doc)) }

server = Server(applications, **server_kwargs)

server.start()

and then

bokeh_serve(curdoc(), port=8888)

…but no joy (page loads but stays blank, no matter what I’ve set curdoc() to). Plus, I’m sure the above uses a bunch of meant-for-internal-use-only APIs, so it’s probably won’t survive a version rev.

Thanks for any help!

–pj

It's not clear to me that creating the doc "outside" like this is going to work. The function that FunctionHandler accepts is supposed to *accept* a doc as its argument, and then *modify* that passed-in doc in whatever way you need (i.e. create and add plots or layouts to it). My guess for why this is not working is this: the server creates a document to server a session, then passes it to the handler to modify. But your lambda drops it on the floor. So the actual document shows is the empty one that you never modified. My first suggestion is to make the function you pass to FunctionHandler actually do the work to create things and attach them to the passed-in doc, inside the function. Testing that would require a more thorough investigation, but we are in the middle of freezing for a release soon, so I can't dig into it just immediately.

Another reason this is problematic is that normally every session gets its own unique document. If this could ever be made to work, I would expect "google doc" type behavior (i.e. view pans the plot, and everyone connected sees the their plot pan too) which is probably not the typically desired behavior.

Bryan

···

On Jun 13, 2016, at 11:22 PM, [email protected] wrote:

Any plans to wrap a nice way to embed a bokeh server in an app? I'd like to use it as a single-user dashboard for some apps I'm writing.

I'm looking for a programmatic way to start up a bokeh server and serve a 'static' (but not really, because it's updating via callbacks) plot or three.

I tried doing:

def bokeh_serve(doc, **server_kwargs):
     from bokeh.server.server import Server
     from bokeh.application import Application
     from bokeh.application.handlers import FunctionHandler

     applications = { '/' : Application(FunctionHandler(lambda x: doc)) }
     server = Server(applications, **server_kwargs)
     server.start()

and then

bokeh_serve(curdoc(), port=8888)

...but no joy (page loads but stays blank, no matter what I've set curdoc() to). Plus, I'm sure the above uses a bunch of meant-for-internal-use-only APIs, so it's probably won't survive a version rev.

Thanks for any help!

  --pj

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/cfc1ad9a-aa09-4042-a494-613a0ab47c93%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks much for the reply! It got me on the right track, so I reworked it to be:

def bokeh_serve(doc_builder, **server_kwargs):

from bokeh.server.server import Server

from bokeh.application import Application

from bokeh.application.handlers import FunctionHandler

applications = { ‘/’ : Application(FunctionHandler(doc_builder)) }

server = Server(applications, **server_kwargs)

server.start()

and then called it like:

bokeh_serve(slider_example, port=8888)

and it worked just fine! Again, many thanks, and I hope your release freeze goes well!

–pj

···

On Wednesday, June 15, 2016 at 3:28:37 PM UTC-4, Bryan Van de ven wrote:

It’s not clear to me that creating the doc “outside” like this is going to work. The function that FunctionHandler accepts is supposed to accept a doc as its argument, and then modify that passed-in doc in whatever way you need (i.e. create and add plots or layouts to it). My guess for why this is not working is this: the server creates a document to server a session, then passes it to the handler to modify. But your lambda drops it on the floor. So the actual document shows is the empty one that you never modified. My first suggestion is to make the function you pass to FunctionHandler actually do the work to create things and attach them to the passed-in doc, inside the function. Testing that would require a more thorough investigation, but we are in the middle of freezing for a release soon, so I can’t dig into it just immediately.

Another reason this is problematic is that normally every session gets its own unique document. If this could ever be made to work, I would expect “google doc” type behavior (i.e. view pans the plot, and everyone connected sees the their plot pan too) which is probably not the typically desired behavior.

Bryan

On Jun 13, 2016, at 11:22 PM, [email protected] wrote:

Any plans to wrap a nice way to embed a bokeh server in an app? I’d like to use it as a single-user dashboard for some apps I’m writing.

I’m looking for a programmatic way to start up a bokeh server and serve a ‘static’ (but not really, because it’s updating via callbacks) plot or three.

I tried doing:

def bokeh_serve(doc, **server_kwargs):

 from bokeh.server.server import Server              
 from bokeh.application import Application    
 from bokeh.application.handlers import FunctionHandler
 applications = { '/' : Application(FunctionHandler(lambda x: doc)) }
 server = Server(applications, **server_kwargs)
 server.start()    

and then

bokeh_serve(curdoc(), port=8888)

…but no joy (page loads but stays blank, no matter what I’ve set curdoc() to). Plus, I’m sure the above uses a bunch of meant-for-internal-use-only APIs, so it’s probably won’t survive a version rev.

Thanks for any help!

–pj


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/cfc1ad9a-aa09-4042-a494-613a0ab47c93%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.