ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Allow support for mutable types as dropdown options

Open CoreyBurger opened this issue 3 years ago • 1 comments

This is a request to reverse #1958. Currently, the options are set using tuples, which are immutable. If you want to have options be driven by data cleanly, there is currently no easy way. You need to store options as a separate variable and then reset the options.

Here is my use case:

  1. Create widget, with base set of options, call it X
  2. Load in data, which has a set of options. Within that list, there are additional options I'd like to be made available
  3. Attempt to edit options, fail
  4. Create a hacky-work around to unzip your tuple of tuples, add the option and put it back together again

The fix is very simple - allow the use of a dictionary as an option, which have excellent and well-tested tools for editing

CoreyBurger avatar Sep 21 '22 15:09 CoreyBurger

A couple of things:

  1. ipywidgets 8.0.2 now allows dictionaries to be used as options again, however
  2. editing the dictionary will not update the options. You'll need to assign the options with a new dictionary to update the options.

The reason for (1) is for better backwards compatibility with 7.x. The reason for (2) is because we don't know when a dictionary has been modified in order to update the options (i.e., when you assign the dictionary, we copy the options out of the dictionary into an internal data structure).

jasongrout avatar Sep 23 '22 00:09 jasongrout