python - Access data from bokeh widgets in a jupyter notebook -
i want use text input widget in jupyter notebook autocompletion. therefore used autocompleteinput()
bokeh.models.widgets.inputs
.
from bokeh.models.widgets.inputs import autocompleteinput bokeh.io import output_notebook bokeh.plotting import show output_notebook() txt_input = autocompleteinput(completions=['val1', 'val2']) show(txt_input)
displaying widget , autocompletion works fine, how can access value of input widget upon change? txt_input.value
returns default value (an empty string).
as of bokeh 0.12.3
, fuller integration of bokeh widgets in jupyter notebook still open issue.
however, there workarounds, though may considered clunky. here customjs
callback can pass widget set value of python value:
from bokeh.models import customjs callback = customjs(code=""" if (ipython.notebook.kernel !== undefined) { var kernel = ipython.notebook.kernel; cmd = "widget_value = '" + cb_obj.value + "'"; kernel.execute(cmd, {}, {}); } """)
the result looks like:
the value of cmd
variable in customjs
code string of python code executed in running jupyter kernel. if need call python function, e.g., too.
Comments
Post a Comment