4

I am working with Jupyter Notebook and am trying to get suggestions to work with a text box as you type characters in. A good example I found is here.

I want to give suggestions as the user types characters, so the list of suggestions will change for every character typed.

I am new to Jupyter and am still trying to learn all the functionality. I need to rely on the base Jupyter tools, such as the ipython widgets (can't install other packages). Any help would be much appreciated.

Adam Sorensen
  • 41
  • 1
  • 3

1 Answers1

2

Have you tried using bokeh's AutocompleteInput for this? Check out the following example from:

Access data from bokeh widgets in a jupyter notebook

from bokeh.models.widgets.inputs import AutocompleteInput
from bokeh.io import output_notebook
from bokeh.plotting import show
from bokeh.models import CustomJS

output_notebook()

callback = CustomJS(code="""
if (IPython.notebook.kernel !== undefined) {
    var kernel = IPython.notebook.kernel;
    cmd = "widget_value = '" + cb_obj.value + "'";
    kernel.execute(cmd, {}, {});
}
""")

txt_input = AutocompleteInput(completions=['val1', 'val2'], callback=callback)

show(txt_input)

print(widget_value)

EDIT: I've just seen you can't install packages. However, the above answer requires bokeh to be installed.

Community
  • 1
  • 1
joergd
  • 490
  • 4
  • 11