Hi,
Having issues with an animation I am plotting in a web app. I followed the gapminder example. I want the user to be able to select a ticker value like its done in the second example, but the second example only gives a static plot on the web app. Neither the slider or the button is working. The first example works, but is stuck on one single ticker. Anyone that can help me on how to sort it out. Why the animation doesnt work when using components, do I need to run a server to run an animation?
Code working:
def animationPlotter(doc):
‘’’
The animationPlotter function
‘’’
wellName = wellnameticker.value
zonesdata = getZonesData(wellName)
dfWellInterp = getWellAnalysisData(wellName)
wellsurvey = getWellSurveyData(wellName)
oildf, waterdf, oilzones, waterzones = getSourceData(dfWellInterp, zonesdata)
sourceoil = ColumnDataSource(data = (oildf.loc[oildf[‘Date’] == dfWellInterp.index[0]]))
sourcewater = ColumnDataSource(data = (waterdf.loc[waterdf[‘Date’] == dfWellInterp.index[0]]))
plotAni = AnimationWellSurveyPlotter(sourceoil, sourcewater, wellsurvey)
datelabel = Label(x = 3600, y = -1.5, text = str(dfWellInterp.index[0]), text_font_size=‘35pt’, text_color=’#eeeeee’)
plotAni.add_layout(datelabel)
def animate_update():
datewell = sliderAni.value + 1
#if datewell > dfWellInterp.index[-1]:
datewell = dfWellInterp.index[0]
sliderAni.value = datewell
def slider_update(attrname, old, new):
datewell = sliderAni.value
datewell = dfWellInterp.index[datewell]
datelabel.text = str(datewell)
data1 = ColumnDataSource(data = (oildf.loc[oildf[‘Date’] == datewell]))
data2 = ColumnDataSource(data = (waterdf.loc[waterdf[‘Date’] == datewell]))
sourceoil.data = data1.data
sourcewater.data = data2.data
sliderAni = Slider(start = 0, end = 14, value = 0, step = 1)
sliderAni.on_change(‘value’, slider_update)
callback_id = None
def animate():
global callback_id
if buttonAni.label == ‘Play’:
buttonAni.label = ‘Pause’
callback_id = curdoc().add_periodic_callback(animate_update, 600)
else:
buttonAni.label = ‘Play’
curdoc().remove_periodic_callback(callback_id)
buttonAni = Button(label=‘Play’, width = 60)
buttonAni.on_click(animate)
Layout = column(column(plotWellSurvey, plotAni), row(sliderAni, buttonAni))
doc.add_root(Layout)
doc.theme = Theme(filename="theme.yaml")
.
.
.
from bokeh.server.server import Server
from tornado.ioloop import IOLoop
def bk_worker():
Can’t pass num_procs > 1 in this configuration. If you need to run multiple
processes, see e.g. flask_gunicorn_embed.py
server = Server({’/animationPlotter’: animationPlotter,
}, io_loop = IOLoop(), allow_websocket_origin = [“localhost:8000”])
server.start()
server.io_loop.start()
from threading import Thread
Thread(target = bk_worker).start()
``
Code not working:
def animationPlotter(wellName):
‘’’
The animationPlotter function
‘’’
zonesdata = getZonesData(wellName)
dfWellInterp = getWellAnalysisData(wellName)
oildf, waterdf, oilzones, waterzones = getSourceData(dfWellInterp, zonesdata)
sourceoil = ColumnDataSource(data = (oildf.loc[oildf[‘Date’] == dfWellInterp.index[0]]))
sourcewater = ColumnDataSource(data = (waterdf.loc[waterdf[‘Date’] == dfWellInterp.index[0]]))
plotAni = AnimationWellSurveyPlotter(sourceoil, sourcewater)
datelabel = Label(x = 3600, y = -1.5, text = str(dfWellInterp.index[0]), text_font_size=‘35pt’, text_color=’#eeeeee’)
plotAni.add_layout(datelabel)
def animate_update():
sliderAni.value = sliderAni.value + 1
def slider_update(attrname, old, new):
datewell = dfWellInterp.index[sliderAni.value]
datelabel.text = str(datewell)
data1 = ColumnDataSource(data = (oildf.loc[oildf[‘Date’] == datewell]))
data2 = ColumnDataSource(data = (waterdf.loc[waterdf[‘Date’] == datewell]))
sourceoil.data = data1.data
sourcewater.data = data2.data
sliderAni = Slider(start = 0, end = 14, value = 0, step = 1)
sliderAni.on_change(‘value’, slider_update)
callback_id = None
def animate():
global callback_id
if buttonAni.label == ‘Play’:
buttonAni.label = ‘Pause’
callback_id = curdoc().add_periodic_callback(animate_update, 600)
else:
buttonAni.label = ‘Play’
curdoc().remove_periodic_callback(callback_id)
buttonAni = Button(label=‘Play’, width = 60)
buttonAni.on_click(animate)
Layout = column(plotAni, row(sliderAni, buttonAni))
return Layout
.
.
.
plotani = animationPlotter(current_well_name)
scriptplotani, divplotani = components(plotani)
``