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
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:
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)
# 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