Update a tab with a new plot

Hello,

I am trying to update a plot within a tab using Bokehjs but it doesn’t seem to work - when I implement the code below, the plot doesn’t update and the tabs also freeze. What am I doing wrong? Thanks for any help!

// Create panels for each plot
   var plot1 = new Bokeh.TabPanel({
         child: timeseries, // timeseries previously created is an instance of Bokeh.Plotting.figure
         title: "Time Series"
   });
    
   var plot2 = new Bokeh.TabPanel({
         child: mapPlot, // mapPlot previously created is an instance of Bokeh.Plotting.figure
         title: "Map"
   });
    
   // Create the Tabs widget and add the panels to it
   var tabs = new Bokeh.Models.Tabs({
         tabs: [timeSeries, mapPlot]
   });
   
   Bokeh.Plotting.show(tabs,'#plotDiv');
    
   var updateButton = plotDiv.append('button')
                             .text('Update')
                             .on('click',function(){
                                newPlot = getNewPlot(); // returns newPlot, an instance of Bokeh.Plotting.figure
                                tabs.tabs[1].child = newPlot;
                                tabs.tabs[1].emit(); 
                             });