I’m trying to create a servable app to show an animation (panel 1.4.1). However I encountered a problem. Consider this code:
from bokeh.models import HoverTool
import numpy as np
import panel as pn
pn.extension()
x = np.linspace(-10, 10, 1000)
f = lambda a: np.cos(a * x)
w = lambda idx: idx / 75 + 1
fig = figure(width=800, height=500)
line = fig.line(x, f(w(0)))
fig.add_tools(HoverTool(
tooltips=[("x", "@x"), ("y", "@y")],
renderers=[line]
))
play = pn.widgets.Player(
value=0,
start=0,
end=150,
step=1,
interval=30,
loop_policy="reflect"
)
def update(val):
line.data_source.data.update({"x": x, "y": f(w(val))})
return fig
binding = pn.bind(update, play)
pane = pn.pane.Bokeh(binding)
template = pn.template.BootstrapTemplate(
title='BootstrapTemplate'
)
template.main.append(
pn.Column(pane, play)
)
template.servable()
By serving the app and starting the animation, after a few cycles it becomes slower and slower. I can actually hear my CPU’s fan getting louder and louder. Sometimes, there is also significant memory increase (although rarely). What’s happening?
Interesting, if I replace pn.Column(pane, play)
with pn.Column(fig, play)
, everything works fine: no slow downs, no memory increase. Other questions: when do I have to use pn.pane.Bokeh
? What does it actually do? When can I get away without using it?