holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.83k stars 519 forks source link

Grouped Select widget orders groups alphabetically #3786

Closed philippjfr closed 2 years ago

philippjfr commented 2 years ago

In this example despite Europe being listed before Africa, Africa is listed first:

select = pn.widgets.Select(name='Select', groups={'Europe': ['Greece', 'France'], 'Africa': ['Algeria', 'Congo']})

select
Screen Shot 2022-08-26 at 17 43 29
mdering commented 2 years ago

I looked into this, and its because bokeh sorts all keys when it dumps the json of the object https://github.com/bokeh/bokeh/blob/a1931d48512a1cb369746025d48344a6ad1834b2/bokeh/core/json_encoder.py#L171 Thus when it encodes the options attribute of the selector, they get sorted. I didnt see any obvious solution to this problem, especially since its upstream in bokeh

jbednar commented 2 years ago

@mattpap?

mattpap commented 2 years ago

It's fixed in bokeh 3.0-rc. bokeh now preserves ordering of data structures. In this case it's insertion order for dicts.