bokeh streaming over websocket

Hi, I have managed to make a working stream of 1D data from flask using bokeh AjaxDataSource to client browser where a bokeh plot is displaying a rolling window of the data.
This works absolutely great.

The problem here is that AjaxDataSource uses long time polling which does not give me the fine grained control i need to sync several different streams.

I would like to instead make use of websockets to push data from the server, such that i can decide when and what to push from server to several streams.

I would like to display the result in a bokeh plot.

I have not been able to find consistent information regarding a websocket datasource for bokeh streaming applications.

Does this exist?

If yes, can anybody point me in direction of an example i can look at?

If it does not exist, can anybody maybe point me towards some information about how this could be implemented using possibly Flask Socket IO or similar?

Thank you very much in advance.

Hi,

Bokeh uses a websocket protocol for Bokeh server apps, that includes sending NumPy arrays and Pandas series directly as binary data automatically when possible, as well as .stream and .patch methods to handle marginal and partial updates very efficiently. So, I'd recommend using the Bokeh server, you can see several examples here:

  https://github.com/bokeh/bokeh/tree/master/examples/app

As well as lots of documentation about running and deploying a Bokeh server here:

  https://bokeh.pydata.org/en/latest/docs/user_guide/server.html

That's what exists and is built in. If you don't want to use a Bokeh server, you could certainly build out this kind of capability yourself by hand. I'd suggest making a Custom Extension subclass of ColumnDataSource so that all the other machinery e.g. for updating plots when data sources change just work, as-is. The docs for creating extensions is here:

  https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html

Thanks,

Bryan

···

On Jul 23, 2018, at 01:21, Bokeh coder <[email protected]> wrote:

Hi, I have managed to make a working stream of 1D data from flask using bokeh AjaxDataSource to client browser where a bokeh plot is displaying a rolling window of the data.
This works absolutely great.

The problem here is that AjaxDataSource uses long time polling which does not give me the fine grained control i need to sync several different streams.
I would like to instead make use of websockets to push data from the server, such that i can decide when and what to push from server to several streams.
I would like to display the result in a bokeh plot.

I have not been able to find consistent information regarding a websocket datasource for bokeh streaming applications.
Does this exist?
If yes, can anybody point me in direction of an example i can look at?
If it does not exist, can anybody maybe point me towards some information about how this could be implemented using possibly Flask Socket IO or similar?

Thank you very much in advance.

--
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/0814b0a5-9a42-4a97-85d8-0f601f6e1d83%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,
Thank you for your reply....I have read through it - looks very nice.
I still dont understand how i can add custom code to the bokeh server
though.
I have a flask app right now which is capable of rendering a stream of jpeg
images.
In short it works like this

@app.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""

return Response(gen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')

here gen is defined as

def gen(camera):
"""Video streaming generator function."""
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

camera.get_frame() basically is a generator that serves a jpeg image when
its ready.
On the client i just have an <img> tag with src set to the /video_feed
resource

Would it be possible to incorporate this in a bokeh server somehow so that
i can also stream and plot bokeh data at the same time through different
handles?

Thanks

···

On Mon, Jul 23, 2018 at 5:17 PM, Bryan Van de ven <[email protected]> wrote:

Hi,

Bokeh uses a websocket protocol for Bokeh server apps, that includes
sending NumPy arrays and Pandas series directly as binary data
automatically when possible, as well as .stream and .patch methods to
handle marginal and partial updates very efficiently. So, I'd recommend
using the Bokeh server, you can see several examples here:

        https://github.com/bokeh/bokeh/tree/master/examples/app

As well as lots of documentation about running and deploying a Bokeh
server here:

        https://bokeh.pydata.org/en/latest/docs/user_guide/server.html

That's what exists and is built in. If you don't want to use a Bokeh
server, you could certainly build out this kind of capability yourself by
hand. I'd suggest making a Custom Extension subclass of ColumnDataSource so
that all the other machinery e.g. for updating plots when data sources
change just work, as-is. The docs for creating extensions is here:

        https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html

Thanks,

Bryan

> On Jul 23, 2018, at 01:21, Bokeh coder <[email protected]> wrote:
>
> Hi, I have managed to make a working stream of 1D data from flask using
bokeh AjaxDataSource to client browser where a bokeh plot is displaying a
rolling window of the data.
> This works absolutely great.
>
> The problem here is that AjaxDataSource uses long time polling which
does not give me the fine grained control i need to sync several different
streams.
> I would like to instead make use of websockets to push data from the
server, such that i can decide when and what to push from server to several
streams.
> I would like to display the result in a bokeh plot.
>
> I have not been able to find consistent information regarding a
websocket datasource for bokeh streaming applications.
> Does this exist?
> If yes, can anybody point me in direction of an example i can look at?
> If it does not exist, can anybody maybe point me towards some
information about how this could be implemented using possibly Flask Socket
IO or similar?
>
> Thank you very much in advance.
>
> --
> 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/0814b0a5-9a42-4a97-85d8-
0f601f6e1d83%40continuum.io.
> For more options, visit https://groups.google.co