Transform data with CDSView

Like this?:

                                              if (source.selection.indices.includes(idx)) {                                            
                                              //if (view.indices.includes(idx)) {

Seems alright. But I have no idea whether itā€™s correct or not because I have no idea what the rest of your code looks like. You should be the judge here.

When I upgrade to 2.2.1 the standalone html files take forever to load or doesnt load at all. Have you had that issue? Works fine on 2.1.1, but upgrading to 2.2.1 and generating the html file causes the file to just load (favicon spinner just spins and plots never show up).

I havenā€™t seen it but I donā€™t generate standalone Bokeh files in my workflow.
The best way to solve that problem is to create a minimal reproducible example and either create a new topic here or post an issue on GitHub.

Hi p-himik and mateusz,

I have upgraded to 2.2.3, my javascript code for CDSView.indices dont work anymore. I tried the above comments, but canā€™t seem to get it working. I added a snipped of code where it crashes. Anyone have a clue how to fix it?

source.attributes.data['Release'].map((x, idx) => {
   if (view.indices.includes(idx)) {
   //if (source.selection.includes(idx)) {

return source.attributes.data['Flux'][idx] = designArea*x
}
})

Presumably you want

source.selection.indices.includes(idx)

But itā€™s hard to say anything for certain without more information.

code where it crashes

If something is crashing, please always state the exact error message. Also as @p-himik suggests, the very best way to help others help you is to provide a complete minimal example so the code can be quickly investigated by simply running it.

Hi Bryan,

You could just try it with the code p-himik helped me with earlier.
I have a bunch of CDSViews in my code getting their values from multiselect tools, since upgrading to the newest bokeh version I keep getting that error. So not entirely sure how to change the code to work on the new version.

import numpy as np

from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CDSView, BooleanFilter, CustomJSTransform, MultiSelect, CustomJS
from bokeh.plotting import figure
from bokeh.transform import transform

p = figure()
ds = ColumnDataSource(dict(x=list(range(10)),
                           y=list(range(10)),
                           names=['a', 'b', 'c', 'c', 'd', 'd', 'a', 'a', 'c', 'c']))
init_val = 'a'
b = BooleanFilter([x == init_val for x in ds.data['names']])

ms = MultiSelect(title='MC Experiment:', value=[init_val],
                 options=sorted(np.unique(ds.data['names'])))

ms.js_on_change('value', CustomJS(args=dict(f=b, source=ds, columnName='names'),
                                  code="""\
                                      const val = cb_obj.value;
                                      f.booleans = (Array.from(source.data[columnName])
                                                    .map(d => val.includes(d != null && d.toString())));
                                      source.change.emit();                                      
                                  """))

view = CDSView(source=ds, filters=[b])
tr = CustomJSTransform(args=dict(view=view),
                       v_func="""\
                           // Cannot filter here because a transform
                           // has to return the same amount of elements.
                           return xs.map((x, idx) => {
                               if (view.indices.includes(idx)) {
                                   return x * 10;
                               }
                               return null;
                           });
                       """)
p.scatter('x', transform('y', tr), view=view, source=ds, color='red')

show(column(p, ms))

@mateusz changed view.indices to be a more memory efficient BitSet data structure for 2.2, but BitSet does not support an includes method. I think you want this instead:

view.indices.get(idx)

which will return true or false depending on whether that index is set or not.