updating bokeh plot with a bokeh widget in jupyter notebook -


i want use bokeh widgets within jupyter notebook update bokeh plot. (somewhat hacky) code looks this:

from bokeh.plotting import figure bokeh.io import output_notebook, push_notebook, show bokeh.models import customjs, slider  output_notebook()  power = 0.5 x = [1,2,3] y = [i**power in x]  fig = figure() plt = fig.circle(x, y)  def update_plot(power):     x = plt.data_source.data['x']     plt.data_source.data['y'] = [i**power in x]     push_notebook(handle=bokeh_handle)     bokeh_handle = show(fig, notebook_handle=true)  ##### new notebook cell #####  callback = customjs(code=""" if (ipython.notebook.kernel !== undefined) {     var kernel = ipython.notebook.kernel;     cmd = "update_plot(" + cb_obj.value + ")";     kernel.execute(cmd, {}, {}); } """)  slider = slider(start=0.1,                  end=1,                 value=1,                 step=.05,                 title="power",                 callback=callback) show(slider) 

the idea js callback slider calls python function update_plot(), changes data of bokeh plot , triggers push_notebook().

however, when move slider, plot not updated, some weird glyphs appear in upper left corner (see red arrow).

executing print(plt.data_source.data['y']) showed me callback , update_plot() called upon slider movement. why plot not updated? or missing here?

(i know can same thing using ipywidgets.interact, want stick bokeh widgets.)

i got plot update expected displaying figure , slider widget within bokeh.layouts.row layout:

from bokeh.plotting import figure bokeh.io import output_notebook, push_notebook, show bokeh.models import customjs, slider bokeh.layouts import row  output_notebook()  power = 0.5 x = [1,2,3] y = [i**power in x]  fig = figure() plt = fig.circle(x, y)  def update_plot(power):     x = plt.data_source.data['x']     plt.data_source.data['y'] = [i**power in x]     push_notebook(handle=bokeh_handle)     ##### new notebook cell #####  callback = customjs(code=""" if (ipython.notebook.kernel !== undefined) {     var kernel = ipython.notebook.kernel;     cmd = "update_plot(" + cb_obj.value + ")";     kernel.execute(cmd, {}, {}); } """)  slider = slider(start=0.1,                  end=1,                 value=1,                 step=.05,                 title="power",                 callback=callback) bokeh_handle = show(row(fig, slider), notebook_handle=true) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -