Not sure if this is possible in jupyter notebook. But I have a list of names (over 700 names) which I would like to user to be able to select based on the MultiSelect tool. The tool is nice because it autofills or finds names close to what is typed. Wanted to add this to a notebook. I assume its not possible to update a variable as done below? Source is kinda disconnected to what is happening into custom js field? Does anyone have an idea how I can have the user find the relevant name easily?
I could be asking something that might not be possible. But I saw some examples on embedding in jupyter notebook.
What I am trying to do is use the value selected in another cell (f.ex in the last cell below, the input_widget.value is empty.
Thanks for this question, I just learned something.
So my current understanding is that output_notebook() will embed standalone html/JS and no longer “talk” to the python variables (so in your case input_widget, as an instance of a python class, its value property never gets altered, but its javascript equivalent does)… i.e. there’s no interaction between the python in your notebook and the html embedded in it.
So that got me thinking that there is probably a way to embed bokeh server within a jupyter notebook, which would then actually alter the state of the python stuff.
from bokeh.plotting import show, output_notebook, output_file
from bokeh.models import AutocompleteInput,CustomJS
from ipywidgets import interact
output_notebook()
def bkapp(doc):
global input_widget
input_widget = AutocompleteInput(completions=['pok', 'wer', 'foo', 'bar', 'baz'], title='test')
doc.add_root(input_widget)
show(bkapp, notebook_url="http://localhost:8890") #need to update notebook_url arg with your localhost url (mine was 8890)
Now what’s pretty hokey about this is the use of a global variable to hold the input_widget and get it outside the bkapp function. Wondering if there’s a cleaner way… but anyway this actually does work:
That’s an interesting use of global to make that happen. I am not sure how I feel about it. In a “normal” notebook app, you would only use the value in widget callbacks that were set up inside the app function.
FWIW we went in the direction of requiring notebook apps to be “encapsulated” inside a function is because allowing portions of the app to be spread across multiple cells that can be re-executed and executed out of order is unreasonable — in the absolutely literal sense of “this is nearly impossible to reason about effectively”. E.g. in such a case it would be trivial to re-execute a cell and end up with a reference to a widget object that is completely divorced from a widget that is actually displayed in another cell, without realizing it. Requiring everything to be bundled together in a single “app function” seemed like the least-worst option to avoid endless confusion.
I guess there has been some work done with jupyter and ipywidgets integration that might lift some of this restriction but I honestly don’t know much about that work.