Different behaviour jupyter notebook / pn.serve for ColumnDataSource.on_change

I have an implementation of a Bokeh plot in panel where I pass the class some ColumnDataSources, which are used to render the graph. The behavior I want is when I change these source’s data, the graph updates. I’m using the ColumnDataSource.on_change for this and I’m finding differences between jupyter notebook and pn.serve, where it doesnt work in jupyter notebook but does when I’m using pn.serve

My code for running in jupyter notebooks:

import panel as pn
import param
import numpy as np
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource


class BKFigure(param.Parameterized):
    do_stuff = param.Action(lambda self: self._new_data())
    def __init__(self, sources, *args, **params):
        self.figure = figure()
        super(BKFigure, self).__init__(*args, **params)
        self.sources = sources
        self.bk_pane = pn.pane.Bokeh(self.figure, sizing_mode='stretch_both')  
        for source in sources.values():
            self.figure.line('x', 'y', source=source)
            source.on_change('data', self._on_change_callback)
    def _new_data(self):
        """mock function to emulate data changing somewhere"""
        print('new data')
        src = self.sources['line1']
        src.data.update({'y': np.random.normal(20, 1, 200)})
        #self.bk_pane.param.trigger('object')  # Triggering the bokeh panel here DOES work while in jupyter notebooks
    def _on_change_callback(self, attr, old, new):
    def panel(self):
        return pn.Row(self.param, self.bk_pane)

x = np.arange(200)
y = np.random.normal(4, 1, 200)
dic = {'x': x, 'y': y}
cds = ColumnDataSource(dic)

y = np.random.normal(6, 1, 200)
dic = {'x': x, 'y': y}
cds1 = ColumnDataSource(dic)

sources = {'line1': cds, 'line2': cds1}

rf = BKFigure(sources)
out = rf.panel()

Where if I uncomment the commented out line it does update, and I can verify that the callback does get called while in jupyter notebooks. When I change to pn.serve(out) everything works fine.

Does anyone know what could be reason for this difference?

My jupyter notebooks runs on python 3.6 and the kernel for my notebook is python 3.7 with:

bokeh                     2.1.1                    py37_0
holoviews                 1.13.3                     py_0
ipykernel                 5.3.0            py37h5ca1d4c_0    conda-forge
ipython                   7.16.1           py37h43977f1_0    conda-forge
panel                     0.9.7                      py_0    pyviz
param                     1.9.3                      py_0    pyviz
pyviz_comms               0.7.5                      py_0    pyviz