Select widget: select none possible? Or distinguish user-interaction value change?

Hi all,

I am making an interface in which a Select() widget will be used to display a list of files that the user can select from a folder which are then loaded into an interactive data visualisation tool. In the UI, the user can also change the folder or search criteria which then updates the file list.

Now, the problem I anticipate is that when the file list gets refreshed, a new file gets, by default, selected, since, as I understand, the Select() widget must always have one item selected (it cannot have no items selected). Because the loading of data into the visualisation can be slow and require a lot of overhead, I want to try to avoid loading files that are not needed when the user has not explicitly clicked on the file they want to load.

For now, I have implemented this by having a separate “load” button under the widget instead of linking the callback to the Select(). But from an UI perspective, it would be nicer if the user did not have to click a separate button after selecting the file they wanted to load.

One way I could see this is using a double click, but I see that this does not seem to be possible (Listbox double-click event · Issue #1248 · jupyter-widgets/ipywidgets · GitHub).

Two other ways I could imagine could be:

  1. “De-selecting”: I could select “none” when I reload options of the Select()
  2. Distinguish, somehow, the setting of the value by code vs. setting of the value via user interaction in the callback

Does anyone know if either of these is possible?

Thanks!
Gary

If I understand your issue correctly, how I run into this quite frequently in my own use cases.

My solution is to always inject/have a value of - present as an option and that is the default for the secondary dropdowns.

eg:

from ipywidgets import widgets

some_list = ['a', 'b', 'c']

some_list = ['-'] + some_list

widgets.Dropdown(
    description='Choose one:',
    value='-',
    options=some_list,
)

image

Then within the code IF the value is - it does nothing, ELSE the heavy computation is performed.

4 Likes

good idea! That will work

1 Like