Loading text file data with buttons in Bokeh

Hi all

I’m trying to get toggle buttons to load up different data sets in bokeh.

Currently I’ve got the two buttons to load up different data sets but they overwrite the existing data

I’d like it if the toggle buttons control if the data is plotted or not (using the toggle state).

Therefore in some cases I would have two lines plotted and in other cases just one line or no lines.

Have I gone about this in a totally wrong way?

I looked hiding the graphs using this example http://stackoverflow.com/questions/32253900/how-to-interactively-display-and-hide-lines-in-a-bokeh-plot

However in the end I’m going to have hundreds of buttons that display data when toggled on. So loading all the data then hiding it didn’t sound like a good idea.

Each of the data sets is stored in a simple two column text file but I’ve put in some random data till I figure out how to read fro a text file using Javascript

Many thanks

from bokeh.io import output_file, show, vform

from bokeh.models import CustomJS, ColumnDataSource, Slider

from bokeh.plotting import figure, output_file, show

from bokeh.models.widgets import Toggle

output_file(“callback.html”)

x = [0]

y = [0]

text_lable=’’

source1 = ColumnDataSource(data=dict(x=x, y=y,legend=text_lable))

plot = figure(plot_width=800, plot_height=400)

plot.line(‘x’, ‘y’, source=source, line_width=3, line_alpha=0.6,legend=“nothing yet”)

plot.yaxis.axis_label=“Cross section (barns)”

plot.xaxis.axis_label=“Energy (barns)”

callback_Ac_225_MT_102 = CustomJS(args=dict(source=source), code="""

var data = source.get(‘data’);

var f = 20

x = data[‘x’]

y = data[‘y’]

x[0]=100

y[0]=300

x[1]=250

y[1]=350

source.trigger(‘change’);

“”")

callback_Ac_225_MT_91 = CustomJS(args=dict(source=source), code="""

var data = source.get(‘data’);

x = data[‘x’]

y = data[‘y’]

console.log(x)

x[0]=15

y[0]=20

x[1]=22

y[1]=45

source.trigger(‘change’);

“”")

toggle_Ac_225_MT_102 = Toggle(label=“Ac_255_MT_102”, type=“success”,callback=callback_Ac_225_MT_102)

toggle_Ac_225_MT_91 = Toggle(label=“Ac_225_MT_91”, type=“success”,callback=callback_Ac_225_MT_91)

layout = vform(plot,toggle_Ac_225_MT_102,toggle_Ac_225_MT_91)

show(layout)

Hi,

Bokeh is a very nice piece of work, thank you all.

I have been using 0.10 to monitor some experimental equipment via streaming plots and bokeh-server. Version 0.11 looks like it brings vast improvements to the server and callbacks to python, perhaps I can finally achieve the things I could not with 0.10.

What I am trying to do is add control of the equipment to the bokeh app via buttons and python server code, but what I’d like is to be able to have multiple users be able to control it and see the same state.
Is this currently possible using only bokeh and not some other framework, django or whatever?

The 0.10 version only monitors, the main issue I had was the URL had session/document ID’s in it each time the system was restarted this would change, making it difficult to tell my colleagues where to point their browser to check the equipment. From a incomplete scan of the new docs it looks like a fixed URL is now possible, is that correct?

Thanks again for all the great work.

Geoff Gillett.

Hi Geoff,

Responses inline:

Hi,

Bokeh is a very nice piece of work, thank you all.

Thanks for the kind words!

I have been using 0.10 to monitor some experimental equipment via streaming plots and bokeh-server. Version 0.11 looks like it brings vast improvements to the server and callbacks to python, perhaps I can finally achieve the things I could not with 0.10.

What I am trying to do is add control of the equipment to the bokeh app via buttons and python server code, but what I’d like is to be able to have multiple users be able to control it and see the same state.
Is this currently possible using only bokeh and not some other framework, django or whatever?

Possibly. But I think more specific details are needed. Things like:

* What kind of auth (if any) is required
* What kind of interface supplies the data? Is it eventing? or is it pull-based?
* What kind of interface do any controls need to trigger? e.g, library, REST API? Is it async or will it block for long durations?

It might be possible to make a pure Bokeh app. But it's also certainly possible to use Bokeh Server together with Django, Flask, etc. if that makes sense (e.g., if you have some strict auth requirements, it probably makes sense to leverage an existing framework for this part, and embed Bokeh server docs in its pages) A nascent example showing a Django integration is here:

  https://github.com/bokeh/bokeh-demos/tree/master/happiness

We have some planned small server features coming up that should make this kind of integration even simpler.

The 0.10 version only monitors, the main issue I had was the URL had session/document ID’s in it each time the system was restarted this would change, making it difficult to tell my colleagues where to point their browser to check the equipment. From a incomplete scan of the new docs it looks like a fixed URL is now possible, is that correct?

Yes, exactly, if you run

  bokeh serve myapp

Then the application shows up under the URL path "/myapp"

Note that every user gets their own "session", but you can certainly share a common backing store, etc. between sessions, so I think this is a technical distinction that should not matter much for you, at least based on the description as I understand it.

Thanks,

Bryan

···

On Jan 10, 2016, at 5:47 PM, Geoff Gillett <[email protected]> wrote:

Thanks again for all the great work.

Geoff Gillett.

--
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/3B1FF905-A3AB-4CE3-A913-2A846A909208%40gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thanks Bryan,
My responses are inline.

Hi Geoff,

Responses inline:

Hi,

Bokeh is a very nice piece of work, thank you all.

Thanks for the kind words!

I have been using 0.10 to monitor some experimental equipment via streaming plots and bokeh-server. Version 0.11 looks like it brings vast improvements to the server and callbacks to python, perhaps I can finally achieve the things I could not with 0.10.

What I am trying to do is add control of the equipment to the bokeh app via buttons and python server code, but what I’d like is to be able to have multiple users be able to control it and see the same state.
Is this currently possible using only bokeh and not some other framework, django or whatever?

Possibly. But I think more specific details are needed. Things like:

Background: We are an experimental physics lab, lots of computer controlled instruments and equipment. Experiments are performed in complete darkness after an experiment is set up we monitor and control things from outside the lab as it runs. We are exploring Jupyter notebooks and bokeh graphs to do this.

The other use case is for the realtime monitoring logging and controlling of ancillary equipment my first taste of Bokeh was for creating streaming plots for a cryostat works great, but would be nice to be able to control the cryostat from the same page.

* What kind of auth (if any) is required

None will work, but I’d like to add some later. There would only ever be three or four users.

* What kind of interface supplies the data? Is it eventing? or is it pull-based?

At the moment python reads the sensors, and pushes them to bokeh-server (0.10) via output_server() and store_objects() once a second. It could easily be changed to pull via a periodic callback or to what ever is best.

* What kind of interface do any controls need to trigger? e.g, library, REST API? Is it async or will it block for long durations?

All the instruments are controlled, and measurement information gathered via python using ayncio so I guess it could potentially block from bokeh’s perspective. Can bokeh co-operate with aysncio event loops?.

It might be possible to make a pure Bokeh app. But it's also certainly possible to use Bokeh Server together with Django, Flask, etc. if that makes sense (e.g., if you have some strict auth requirements, it probably makes sense to leverage an existing framework for this part, and embed Bokeh server docs in its pages) A nascent example showing a Django integration is here:

What I’d like to do is use the minimum number of frameworks to lessen the learning curve not only for myself but for research students that may follow, as it stands they need to know python, which is not a given, and understand the bokeh api.

The key functionality I require is that the widget state be shared across the few users. The canonical example being a toggle button, if one users turns it on, turning on a piece of equipment say, I need the other users to see the new state in any browser window they may have open or any they open after the state change.

From Havoc’s answer it appears there are two options: (I have not had a chance to test either yet)

1) All users have the same session, this sounds like it would work but has the inconvenience of needing to know the sessionID to connect.

2) Global server code and state that gets set up via on_session_load() (or what ever the hook is).
    Here I am not sure that they would see the sate change. But have not had the chance to explore it.

All advice appreciated.

Geoff.

···

On 15 Jan 2016, at 3:34 AM, Bryan Van de Ven <[email protected]> wrote:

On Jan 10, 2016, at 5:47 PM, Geoff Gillett <[email protected]> wrote:

  https://github.com/bokeh/bokeh-demos/tree/master/happiness

We have some planned small server features coming up that should make this kind of integration even simpler.

The 0.10 version only monitors, the main issue I had was the URL had session/document ID’s in it each time the system was restarted this would change, making it difficult to tell my colleagues where to point their browser to check the equipment. From a incomplete scan of the new docs it looks like a fixed URL is now possible, is that correct?

Yes, exactly, if you run

  bokeh serve myapp

Then the application shows up under the URL path "/myapp"

Note that every user gets their own "session", but you can certainly share a common backing store, etc. between sessions, so I think this is a technical distinction that should not matter much for you, at least based on the description as I understand it.

Thanks,

Bryan

Thanks again for all the great work.

Geoff Gillett.

--
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/3B1FF905-A3AB-4CE3-A913-2A846A909208%40gmail.com.
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/854D020C-09CA-4F1F-AE9B-F379B27CCE8A%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.