jupyter_bokeh: push_notebook doesn't update in VSCode .ipynb
I am not able to get the various push_notebook examples to update when run as .ipynb files from VSCode. They work fine when run from a Jupyter notebook. Below is a simple standard example that runs in a Jupyter notebook but not in VSCode. I need to do Bokeh animation from within a VSCode development environment.
Isn’t this supposed to work as a cell in an .ipynb file executed in VSCode?
from bokeh.plotting import figure, show, output_notebook
from bokeh.models import ColumnDataSource
from bokeh.layouts import layout
from bokeh.io import push_notebook
import numpy as np
from time import sleep
# Output to Jupyter Notebook
output_notebook()
# Prepare some data
x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))
# Create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
# Add a line renderer with legend and line thickness
p.line('x', 'y', source=source, legend_label="Temp.", line_width=2)
# Show the results
handle = show(p, notebook_handle=True)
# Update the plot
def update_plot(n_steps, sleep_time):
for i in range(n_steps):
y = np.sin(x + i/10.0)
source.data = dict(x=x, y=y)
push_notebook(handle=handle)
sleep(sleep_time)
update_plot(100, 0.1)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 18 (12 by maintainers)
This works! Thanks, I had given up. 😊
While it’d be nice for it to work by default. It is possible to work around it using jupyter_bokeh as described by @bryevcv . Please check this stack overflow questions if you stumble upon the issue and need a solution right now: https://stackoverflow.com/questions/77841047/how-to-update-a-bokeh-plot-inside-vscode-jupyter-notebook/78556116#78556116 https://stackoverflow.com/questions/73260026/bokeh-interactive-slider-in-vscode/78556052#78556052