Why is this legend going into party mode rotating across colors when using a slider with a callback?

Hi tvkyq,

It’s possible-- not yet definite-- that there may be a bug here in the way that categorical legends behave when CDSViews are involved. I need to work up a minimal example to prove it, and decide what elements are important to the problem; my testing so far suggests that the factor_cmap isn’t an issue, and if we instead add a column of explicitly defined colors to your data source, the same thing occurs. Anyway, I’ll be working on that and submitting a GitHub issue if we do determine that it’s not behaving like it ought, and I’ll update this thread with a link to that GH issue.

In the meantime, we have a couple options for workarounds. We could revisit the original example you cited in your other post, the example in which a new figure is being drawn on each update. That’s possible, but I imagine your real-life end goal is more complicated than the apples, bananas, and oranges you have here, and I’d be wary about scaling.

Perhaps a better option would be to avoid using a CDSView, instead using your original data to construct one large, source-of-truth CDS. Then, with each update, your callback would build a CDS that’s a subset of that untouched original. The subset CDS could then be assigned to be the data source for your circle glyph.

I hope that makes sense, with the caveat that I have not built a working example of it. I believe it will get around this issue of the grouped categorical legend and the colors assigned to legend items not matching up. Please give it a shot and let us know what questions you have along the way. Thanks for your patience while this was investigated!