Integrate Bokeh server into existing Tornado app

Hi there,

We currently develop a climate science desktop application that uses a Python back-end and a TypeScript/React front-end running on Electron. In the back-end we use a Tornado server that provides a WebSocket and REST API to the front-end. We now like to integrate charting into our app and we are in the process of comparing various solutions. Bokeh seems to nicely fit into our current app design.

Is it easily possible to hook the Bokeh server into the IOLoop of an existing Tornado app, so that we can run Bokeh Python modules and have Bokeh JS plots in our front-end? And if so, what would be the preferable way do it?

Cheers

Norman

Hi,

Yes, there is an example of that exact use case here:

  https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/tornado_embed.py

Thanks,

Bryan

···

On Apr 1, 2017, at 04:02, Norman Fomferra <[email protected]> wrote:

Hi there,

We currently develop a climate science desktop application that uses a Python back-end and a TypeScript/React front-end running on Electron. In the back-end we use a Tornado server that provides a WebSocket and REST API to the front-end. We now like to integrate charting into our app and we are in the process of comparing various solutions. Bokeh seems to nicely fit into our current app design.

Is it easily possible to hook the Bokeh server into the IOLoop of an existing Tornado app, so that we can run Bokeh Python modules and have Bokeh JS plots in our front-end? And if so, what would be the preferable way do it?

Cheers
    Norman

--
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/1be4dbaa-3c47-4b68-b01d-23d9ab1e189f%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Great, thanks! :slight_smile:

···

Am Samstag, 27. Mai 2017 04:59:38 UTC+2 schrieb Bryan Van de ven:

Hi,

Yes, there is an example of that exact use case here:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/tornado_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/tornado_embed.py)

Thanks,

Bryan

On Apr 1, 2017, at 04:02, Norman Fomferra [email protected] wrote:

Hi there,

We currently develop a climate science desktop application that uses a Python back-end and a TypeScript/React front-end running on Electron. In the back-end we use a Tornado server that provides a WebSocket and REST API to the front-end. We now like to integrate charting into our app and we are in the process of comparing various solutions. Bokeh seems to nicely fit into our current app design.

Is it easily possible to hook the Bokeh server into the IOLoop of an existing Tornado app, so that we can run Bokeh Python modules and have Bokeh JS plots in our front-end? And if so, what would be the preferable way do it?

Cheers

Norman


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/1be4dbaa-3c47-4b68-b01d-23d9ab1e189f%40continuum.io.

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

Hello I think I have a somewhat similar use case and I am having a hard time with this example. I havn’t been using tornado for very long so maybe I am missing something but…

That example seems like it is meant for building an application from scratch using Bokeh but what if you already have a pretty complex tornado application and WebsocketHandler already setup using vanilla Tornado?

A brief description of my tornado app: (I’m no expert but this i what I figured out so far)

I have an application setup using a simple JSON message protocol like this

Enter code here…

``
{“action”: “event_name”,
“optional_uuid”: “uuid”,
“data”: {data_keys: values}}

  • My WebSocketHandler class passes the incoming messages off to an application(not Tornado) Model object somewhat similar to Almar Klein’s Flexx library but much more stripped down.
  • The application Model is Instantiated on the WebsocketHandler and has a hierarchy of Model objects that each render their own portion of UI over the websocket.
  • Each model has a UUID that it registers with the top App model and each model can also register event handlers on themselves or other models. somewhat similar to flexx as well.
  • If the incoming message has a UUID key in it it goes directly to that Model otherwise it rolls through the object tree until it hits an event with the same name as the action key in the message.
  • The model does whatever it needs to do then sends back a message to update client if necessary.

I was hoping that I could just add a bokeh plot model to the appropriate spot in my model tree where I want to render it (which I know I could do statically) and let it keep it’self up to date over the same websocket connection.

on each model where I want the plot there is also a dataframe that i render to the UI as a table.

I have some form fields that I use to edit the table (i want to replace this with the table Widget) which updates the Dataframe.

I want the plot to update with the DataFrame (Using a Column Data source obviously)

So I guess I’m wondering If I can or should Swap out the regular Tornado Application and Server objects for the Bokeh ones?

Then What do I do with my WebsocketHandler and current messaging architecture?

Is there a corollary to the WebsocketHandler in Bokeh that I can extend?

Then how would I tell it to accept and differentiate between my regular app’s messages and Bokeh’s?

For context: The whole purpose of the App is to create a UI over specially formatted configuration text files that have groupings of key value fields and tabular data.

···

On Friday, May 26, 2017 at 10:59:38 PM UTC-4, Bryan Van de ven wrote:

Hi,

Yes, there is an example of that exact use case here:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/tornado_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/tornado_embed.py)

Thanks,

Bryan

On Apr 1, 2017, at 04:02, Norman Fomferra [email protected] wrote:

Hi there,

We currently develop a climate science desktop application that uses a Python back-end and a TypeScript/React front-end running on Electron. In the back-end we use a Tornado server that provides a WebSocket and REST API to the front-end. We now like to integrate charting into our app and we are in the process of comparing various solutions. Bokeh seems to nicely fit into our current app design.

Is it easily possible to hook the Bokeh server into the IOLoop of an existing Tornado app, so that we can run Bokeh Python modules and have Bokeh JS plots in our front-end? And if so, what would be the preferable way do it?

Cheers

Norman


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/1be4dbaa-3c47-4b68-b01d-23d9ab1e189f%40continuum.io.

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

Hi,

We are in the middle of a release sprint so I can't say much immediately, but I will say that Bokeh sets up and manages its own websocket. Everything that happens between BokehJS and a python Bokeh app is via a defined protocol over this websocket. Anything that does not adhere to that protocol would simply be regarded as protocol corruption, and the session would be immediately terminated. I don't think there is much chance of making any approach that involves sharing a web socket work.

Moreover, the mechanism you describe in your bullet points seems largely like a duplication of the Bokeh server. The entire point of the Bokeh server is to synchronize state between python and JS and execute code on both ends in response to updates. If you already have a completely different mechanism for doing basically that same thing, and you are committed to using it, then you are probably better of using BokehJS directly as a pure JavaScript library that you call out to and adapt to you existing framework, rather than trying to integrate a Bokeh server alongside.

Thanks,

Bryan

···

On Jun 9, 2017, at 16:17, [email protected] wrote:

Hello I think I have a somewhat similar use case and I am having a hard time with this example. I havn't been using tornado for very long so maybe I am missing something but..
That example seems like it is meant for building an application from scratch using Bokeh but what if you already have a pretty complex tornado application and WebsocketHandler already setup using vanilla Tornado?

A brief description of my tornado app: (I'm no expert but this i what I figured out so far)

I have an application setup using a simple JSON message protocol like this

Enter code here...

{"action": "event_name",
"optional_uuid": "uuid",
"data": {data_keys: values}}

  • My WebSocketHandler class passes the incoming messages off to an application(not Tornado) Model object somewhat similar to Almar Klein's Flexx library but much more stripped down.
  • The application Model is Instantiated on the WebsocketHandler and has a hierarchy of Model objects that each render their own portion of UI over the websocket.
  • Each model has a UUID that it registers with the top App model and each model can also register event handlers on themselves or other models. somewhat similar to flexx as well.
  • If the incoming message has a UUID key in it it goes directly to that Model otherwise it rolls through the object tree until it hits an event with the same name as the action key in the message.
  • The model does whatever it needs to do then sends back a message to update client if necessary.

I was hoping that I could just add a bokeh plot model to the appropriate spot in my model tree where I want to render it (which I know I could do statically) and let it keep it'self up to date over the same websocket connection.

on each model where I want the plot there is also a dataframe that i render to the UI as a table.
I have some form fields that I use to edit the table (i want to replace this with the table Widget) which updates the Dataframe.
I want the plot to update with the DataFrame (Using a Column Data source obviously)

So I guess I'm wondering If I can or should Swap out the regular Tornado Application and Server objects for the Bokeh ones?

Then What do I do with my WebsocketHandler and current messaging architecture?

Is there a corollary to the WebsocketHandler in Bokeh that I can extend?

Then how would I tell it to accept and differentiate between my regular app's messages and Bokeh's?

For context: The whole purpose of the App is to create a UI over specially formatted configuration text files that have groupings of key value fields and tabular data.

On Friday, May 26, 2017 at 10:59:38 PM UTC-4, Bryan Van de ven wrote:
Hi,

Yes, there is an example of that exact use case here:

        https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/tornado_embed.py

Thanks,

Bryan

> On Apr 1, 2017, at 04:02, Norman Fomferra <[email protected]> wrote:
>
> Hi there,
>
> We currently develop a climate science desktop application that uses a Python back-end and a TypeScript/React front-end running on Electron. In the back-end we use a Tornado server that provides a WebSocket and REST API to the front-end. We now like to integrate charting into our app and we are in the process of comparing various solutions. Bokeh seems to nicely fit into our current app design.
>
> Is it easily possible to hook the Bokeh server into the IOLoop of an existing Tornado app, so that we can run Bokeh Python modules and have Bokeh JS plots in our front-end? And if so, what would be the preferable way do it?
>
> Cheers
> Norman
>
> --
> 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/1be4dbaa-3c47-4b68-b01d-23d9ab1e189f%40continuum.io.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
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/60929f9a-539f-44a0-9847-31ba50399b32%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

@brycevtr250, I imagine, a good approach would be to register the Bokeh
Server as secondary Tornado Application on the same IOLoop. Your main
Tornado app then communicates with the Bokeh app to render plots from your
app's state data.

Hi,

We are in the middle of a release sprint so I can't say much immediately,
but I will say that Bokeh sets up and manages its own websocket. Everything
that happens between BokehJS and a python Bokeh app is via a defined
protocol over this websocket. Anything that does not adhere to that
protocol would simply be regarded as protocol corruption, and the session
would be immediately terminated. I don't think there is much chance of
making any approach that involves sharing a web socket work.

Moreover, the mechanism you describe in your bullet points seems largely
like a duplication of the Bokeh server. The entire point of the Bokeh
server is to synchronize state between python and JS and execute code on
both ends in response to updates. If you already have a completely
different mechanism for doing basically that same thing, and you are
committed to using it, then you are probably better of using BokehJS
directly as a pure JavaScript library that you call out to and adapt to you
existing framework, rather than trying to integrate a Bokeh server
alongside.

Thanks,

Bryan

Hello I think I have a somewhat similar use case and I am having a hard

time with this example. I havn't been using tornado for very long so maybe
I am missing something but..

That example seems like it is meant for building an application from

scratch using Bokeh but what if you already have a pretty complex tornado
application and WebsocketHandler already setup using vanilla Tornado?

A brief description of my tornado app: (I'm no expert but this i what I

figured out so far)

I have an application setup using a simple JSON message protocol like this

Enter code here...

{"action": "event_name",
"optional_uuid": "uuid",
"data": {data_keys: values}}

      • My WebSocketHandler class passes the incoming messages off to an

application(not Tornado) Model object somewhat similar to Almar Klein's
Flexx library but much more stripped down.

      • The application Model is Instantiated on the WebsocketHandler and

has a hierarchy of Model objects that each render their own portion of UI
over the websocket.

      • Each model has a UUID that it registers with the top App model

and each model can also register event handlers on themselves or other
models. somewhat similar to flexx as well.

      • If the incoming message has a UUID key in it it goes directly to

that Model otherwise it rolls through the object tree until it hits an
event with the same name as the action key in the message.

      • The model does whatever it needs to do then sends back a message

to update client if necessary.

I was hoping that I could just add a bokeh plot model to the appropriate

spot in my model tree where I want to render it (which I know I could do
statically) and let it keep it'self up to date over the same websocket
connection.

on each model where I want the plot there is also a dataframe that i

render to the UI as a table.

I have some form fields that I use to edit the table (i want to replace

this with the table Widget) which updates the Dataframe.

I want the plot to update with the DataFrame (Using a Column Data source

obviously)

So I guess I'm wondering If I can or should Swap out the regular Tornado

Application and Server objects for the Bokeh ones?

Then What do I do with my WebsocketHandler and current messaging

architecture?

Is there a corollary to the WebsocketHandler in Bokeh that I can extend?

Then how would I tell it to accept and differentiate between my regular

app's messages and Bokeh's?

For context: The whole purpose of the App is to create a UI over

specially formatted configuration text files that have groupings of key
value fields and tabular data.

Hi,

Yes, there is an example of that exact use case here:

        https://github.com/bokeh/bokeh/blob/master/examples/howto/

server_embed/tornado_embed.py

Thanks,

Bryan

>
> Hi there,
>
> We currently develop a climate science desktop application that uses a

Python back-end and a TypeScript/React front-end running on Electron. In
the back-end we use a Tornado server that provides a WebSocket and REST API
to the front-end. We now like to integrate charting into our app and we are
in the process of comparing various solutions. Bokeh seems to nicely fit
into our current app design.

>
> Is it easily possible to hook the Bokeh server into the IOLoop of an

existing Tornado app, so that we can run Bokeh Python modules and have
Bokeh JS plots in our front-end? And if so, what would be the preferable
way do it?

>
> Cheers
> Norman
>
> --
> 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/co

ntinuum.io/d/msgid/bokeh/1be4dbaa-3c47-4b68-b01d-23d9ab1e189f%40continuum.io
.

> For more options, visit https://groups.google.com/a/co

ntinuum.io/d/optout.

--
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/co

ntinuum.io/d/msgid/bokeh/60929f9a-539f-44a0-9847-31ba50399b32%40continuum.io
.

···

Am 09.06.2017 11:27 nachm. schrieb "Bryan Van de ven" <[email protected]>:

On Jun 9, 2017, at 16:17, [email protected] wrote:
On Friday, May 26, 2017 at 10:59:38 PM UTC-4, Bryan Van de ven wrote:
> On Apr 1, 2017, at 04:02, Norman Fomferra <[email protected]> wrote:
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
You received this message because you are subscribed to a topic in the
Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this topic, visit https://groups.google.com/a/co
ntinuum.io/d/topic/bokeh/CxFVmBMxl74/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
bokeh+unsub[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/co
ntinuum.io/d/msgid/bokeh/BCEBD18B-BE35-48F7-89FE-734A6E81F6F7%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thanks I will look into this.

You can definitely piggyback a Bokeh server programmaticaly on an existing Tornado IOLoop, there is an example in the repo:

  https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/tornado_embed.py

But that won't get you a single websocket. I re-iterate that there almost certainly no way to make a single web socket work currently. The only path I could imagine is to tunnel Bokeh protocol messages as content inside your other protocol messages, that you then unpack and apply them to the document by hand. But even this would require modification to the current server code.

Thanks,

Bryan

···

On Jun 11, 2017, at 00:39, [email protected] wrote:

Thanks I will look into this.

--
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/a5603431-90cc-4587-8244-091ddf8e7b2e%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.