Error with categorial data if range is not the same as source

Hi,

I get an error if the figure x_range categorial values are not the same as the source. Below I use a CDSView to filter data to only show Apples category. If one does not want empty space for the other categories in fruits, it would be natural to change the figure x_range to only the fruits that are filtered. But this gives an error in the browser:

Bokeh Error

undefined is not an object (evaluating 'this._mapping[t[0]].value')

Not sure if I am doing something wrong? Any help appreciated. Thanks

···

from bokeh.core.properties import value

from bokeh.io import show, output_file

from bokeh.models import ColumnDataSource, HoverTool, CDSView, BooleanFilter

from bokeh.plotting import figure

from bokeh.transform import dodge

output_file(“dodged_bars.html”)

fruits = [‘Apples’, ‘Pears’, ‘Nectarines’, ‘Plums’, ‘Grapes’, ‘Strawberries’]

years = [‘2015’, ‘2016’, ‘2017’]

data = {‘fruits’ : fruits,

‘2015’ : [2, 1, 4, 3, 2, 4],

‘2016’ : [5, 3, 3, 2, 4, 6],

‘2017’ : [3, 2, 4, 4, 5, 3]}

source = ColumnDataSource(data=data)

fruits2 = [‘Apples’] # new x_range to use

view=CDSView(source = source, filters=[BooleanFilter(

[True if fruit == fruits2[0] else False for fruit in source.data[‘fruits’]])])

p = figure(x_range=fruits2, y_range=(0, 10), plot_height=250,

title=“Fruit Counts by Year”,

toolbar_location=None, tools="")

r_15=p.vbar(x=dodge(‘fruits’, -0.25, range=p.x_range), top=‘2015’,

width=0.2, source=source, color="#c9d9d3",

legend=value(“2015”), fill_alpha = 0.6, hover_alpha = 1,

hover_color = “#c9d9d3”, view = view)

r_16=p.vbar(x=dodge(‘fruits’, 0.0, range=p.x_range), top=‘2016’,

width=0.2, source=source, color="#718dbf",

legend=value(“2016”), fill_alpha = 0.6, hover_alpha = 1,

hover_color ="#718dbf", view = view)

r_17=p.vbar(x=dodge(‘fruits’, 0.25, range=p.x_range), top=‘2017’,

width=0.2, source=source, color="#e84d60",

legend=value(“2017”), fill_alpha = 0.6, hover_alpha = 1,

hover_color = “#e84d60”, view = view)

p.x_range.range_padding = 0.1

p.xgrid.grid_line_color = None

p.legend.location = “top_left”

p.legend.orientation = “horizontal”

p.add_tools(HoverTool(renderers = [r_15,r_16,r_17],tooltips= None))

show§