solara icon indicating copy to clipboard operation
solara copied to clipboard

Change select values typing

Open itepifanio opened this issue 2 years ago • 2 comments

I'm not sure if I should have opened this issue in solara's repo since it seems to use reacton/ipyvuetify, but I would like to suggest changing the Select values parameter from List[T] to Union[List[T], Dict[T, Any]].

Allowing dict will enable users to display a good label for the user while using a good typing for the developer. Ipywidgets also allows dict usage in their select. In the next example the user will see the options 'unlabeled, label 01 and label 02 and when iterating with this options the backend receives None or an integer 1 or 2 to work with it.

import ipywidgets as widgets

select = widgets.Select(options={'unlabeled': None, 'label 01': 1, 'label 02': 2}, description='')

select.observe(lambda x: print(x['new']), names='value')

select

itepifanio avatar Oct 19 '23 16:10 itepifanio

I like this idea. But I think you mean Union[List[T], Dict[str, T]] right? Because the T should match the type of value, and the string key in the dict will be the label. Good thing we support Python >= 3.6, so we can rely on stable dict order.

maartenbreddels avatar Oct 20 '23 14:10 maartenbreddels

@maartenbreddels to change this I would need to change the ipyvuetify package. It seems that the code gets the traitlets from vuetify_api.json, but it's not clear to me how this file is generated, do you have any docs related to this?

itepifanio avatar Jan 26 '24 14:01 itepifanio