Allow Select to accept non-string option values
See original GitHub issueI think it would be useful to have the Select widget values to be any object: for example it maybe useful for the select.value
to point to a function.
Consider this (hypothetical) instance of a Select widget:
select = Select(title="Options:",
value=do_1,
options=[(do_1,"option_1"), (do_2,"option_2"), (do_3,"option_3"), (do_4,"option_4")])
where do_n
is a previously defined function. I have chosen to have (value, label)
pairs as options so a user could select an option and the relevant function could be accessed by accessing the value attribute of my widget (i.e., select.value
). Currently this isn’t supported and I will have to store my functions in a dictionary with suitable keys selected by the widget.
There is a related issue (bug?) that the value attribute fed to initiate the Select widget can only be a String. It would be nice to to support this kind of functionality:
select = Select(title="Options:",
value=1,
options=[(1,"option_1"), (2,"option_2"), (3,"option_3"), (4,"option_4")])
Currently this does not work but in some instances is required (i.e., when using the select widget to access a list and a default value is required).
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (7 by maintainers)
Top GitHub Comments
@FChmiel no I think I misinterpreted this:
to mean there is a related GH issue here somewhere.
This issue is great for figuring out how to expand supported values in
Select
The Param library works like this, with the value of a Selector being an actual item (integer, function, etc.) and the Panel library being used to make a corresponding Bokeh widget. See e.g. the
select_fn
parameter in the Panel Param docs. This doesn’t change whether Bokeh itself could or should act like this, but I think it does let you do the sort of thing you’re asking for, and it might be an approach to consider.