我正在使用 Jupyter Notebook 并尝试在您输入字符时获得有关使用文本框的建议。我发现的一个很好的例子是 here.
我想在用户键入字符时提供建议,因此建议列表会根据键入的每个字符而变化。
我是 Jupyter 的新手,仍在努力学习所有功能。我需要依赖基本的 Jupyter 工具,例如 ipython 小部件(无法安装其他包)。任何帮助将非常感激。
最佳答案
您是否尝试过为此使用 Bokeh 的 AutocompleteInput
?
查看以下示例:
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)
编辑:我刚刚看到您无法安装软件包。但是,上述答案需要安装 bokeh
。
关于javascript - Jupyter 自动填充建议文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37685924/