Often, you want the user to choose n options (where n is small-ish) from a very large (hundreds or thousands) number of possibilities. Good UX around this dictates that the user should be able to search for the options they want.
This gist puts together a minimal example of binding a search field with multiple checkboxes using ipywidgets.
widget = multi_checkbox_widget(['hello', 'world'])
widget # Display the widget
To get the selected options:
selected_options = [widget.description for widget in w.children[1].children if widget.value]
-
This is in need of some layout/CSS TLC.
-
At the moment, we just use difflib from the standard library for searching through the options. It mostly works, but I don't think it's what difflib is supposed to be used as. Using a different search algorithm might lead to better results.
Hey! @pbugnion
I don't know if it is too late, but I think there is a simple way to improve the search algorithm. It would be to rewrite the close_matches
definition as it follows:
close_matches = sorted(list(filter(lambda x: search_input in x, descriptions)))
With that code you manage to extract all the words that contain the search_input, and besides, words are showed in alphabetical order.
I hope it helps.