bokeh images during dataframe iteration

Hello all,

Is it possible to generate a bokeh image per record during iteration of a python data frame? I would like to generate a single image with a button that the user clicks after which the next record in the data frame is used to create another bokeh image with an associated button. I would like the iteration to pause and wait for the user to “click” the button of a given image before moving to the next.

The critical section of code follows (I am using Jupyter notebook):

defined callback function

def callback(airport, acid):
line = airport + “,” + acid + “\n”
with open(’/home/markedFlights.csv’, ‘a’) as myfile:
myfile.write(line)

for airportname, selection in maDF.groupby([‘FLIGHT_ID’,‘AIRPORT’,‘ACID’]):

# generate a separate chart for each grouping
source = ColumnDataSource(selection)

p = figure()
p.y_range = Range1d(0,6000)
p.circle(x='TIME', y='ALTITUDE_AGL', source=source, size=10, color='green')
p.title.text = "Airport: " + airportname[1] + ",Aircraft ID: " + airportname[2]
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Altitude (AGL)'

button = Button(label="Mark Flight", button_type="success")    
button.js_on_event(events.ButtonClick, callback(airportname[1], airportname[2]))

# make a grid
grid = gridplot([p, button], ncols=1, nrows=2, plot_width=600, plot_height=600)
show(grid)

# I would like to 'pause' at this image so user could click button before
# moving to next record in data frame for imagine with an associated button as well

``

Hi,

First off, to use js_on_event requires running a Bokeh server application. It's simple to embed Bokeh apps in notebooks now, but you should probably acquaint yourself with a working example first so you can ask more pointed questions:

  https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb

and more generally, about the Bokeh server:

  Bokeh server — Bokeh 3.3.2 Documentation

Thanks,

Bryan

···

On Sep 13, 2018, at 13:06, [email protected] wrote:

Hello all,

Is it possible to generate a bokeh image per record during iteration of a python data frame? I would like to generate a single image with a button that the user clicks after which the next record in the data frame is used to create another bokeh image with an associated button. I would like the iteration to pause and wait for the user to "click" the button of a given image before moving to the next.

The critical section of code follows (I am using Jupyter notebook):

# defined callback function
def callback(airport, acid):
    line = airport + "," + acid + "\n"
    with open('/home/markedFlights.csv', 'a') as myfile:
        myfile.write(line)

for airportname, selection in maDF.groupby(['FLIGHT_ID','AIRPORT','ACID']):

    # generate a separate chart for each grouping
    source = ColumnDataSource(selection)

    p = figure()
    p.y_range = Range1d(0,6000)
    p.circle(x='TIME', y='ALTITUDE_AGL', source=source, size=10, color='green')
    p.title.text = "Airport: " + airportname[1] + ",Aircraft ID: " + airportname[2]
    p.xaxis.axis_label = 'Time'
    p.yaxis.axis_label = 'Altitude (AGL)'

    button = Button(label="Mark Flight", button_type="success")
    button.js_on_event(events.ButtonClick, callback(airportname[1], airportname[2]))

    # make a grid
    grid = gridplot([p, button], ncols=1, nrows=2, plot_width=600, plot_height=600)
    show(grid)
   
    # I would like to 'pause' at this image so user could click button before
    # moving to next record in data frame for imagine with an associated button as well

--
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/da7dec4e-8e38-4848-b143-492d795676f8%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.