I posted this to StackOverflow a few days ago and haven’t gotten any response at all, so I’m hoping you guys here can find where I’m going wrong. . I do see something similar has been asked here before, but not quite my use case. Python Bokeh: Interactive multi_line graph with checkbox widget to show/hide lines not generating graph. Is there a line limit? - Stack Overflow
(Pasted from SO post)
I’m building an interactive multi_line graph where the user will select which lines are displayed based on a combination of two CheckBoxGroups and a RadioGroup. There are a total of 111 possible lines to generate, and up to half of them viewed at one time (although no user would actually want to do that). Visibility is changed with a corresponding alpha in the line_alpha parameter. I was having luck generating the lines with p.line in a loop for every parameter but could not get interaction working cleanly. I tried MultiLine but couldn’t use an array for line_alpha and couldn’t generate the graph, so now I am using multi_line. The array of alpha values is updating correctly with the widget interaction, but again the graph is not generating even when taking out the line_alpha parameter. Is there some limit to the amount of data that will be graphed at one time? Or, more likely, am I making a simple mistake in my code? I’ve been fiddling with this for days but can’t track down the issue. There are no errors showing in the console. Below is the relevant sections of code (I’ve trimmed out any data wrangling). Also keep in mind the column names (other than ‘time’) are not known until runtime, so I can’t rely on hard coding that.
class LineGraphSuite(object):
def __init__(self, file):
st = SetupTable(file)
self.tableAndInfo = st.setup()
self.player_group = CheckboxGroup(labels=PLAYER_LIST, active=[0])
self.param_group = CheckboxGroup(labels=PARAM_LIST, active=[0])
self.dimension_group = RadioGroup(labels=DIMENSION_LIST, active=0)
self.player_group.on_change('active', self.update)
self.param_group.on_change('active', self.update)
self.dimension_group.on_change('active', self.update)
self.alphaList = self.generateAlphaArray(["ball_linearVelocity2D"])
self.src = self.generateLineGraphData() # self.src is a pandas dataframe
self.drawLineGraph()
self.controls = Column(self.player_group, self.param_group, self.dimension_group)
self.layout = column(self.controls, self.p)
def drawLineGraph(self):
"""Generates multi line graph with every parameter and array of alpha values."""
# Initialize figure to add upon
print("Drawing line graph.")
self.p = figure(plot_width = 1300, plot_height = 400, title = "Test Line Chart")
# Draw multi line graph and use alpha array to update visibility of lines
arr = []
for entry in self.src: arr.append('time')
df = self.tableAndInfo[0]
xs = df[arr]
self.p.multi_line(xs=xs, ys=self.src, line_alpha=self.alphaList)
def update(self, attr, old, new):
"""Called in widget change events. Updates alpha array based on selected checkbox and radio buttons."""
param = self.param_group.labels[self.param_group.active]
dimension = self.dimension_group.labels[self.dimension_group.active]
players = [self.player_group.labels[i] for i in self.player_group.active]
paramList = []
for player in players:
print("Update: ", player, param, dimension)
paramList.append(self.createColumnName(player, param, dimension))
self.alphaList = self.generateAlphaArray(paramList)
def generateLineGraph(self):
"""Creates graph on page"""
print("Generating graph on page")
curdoc().add_root(self.layout)
What generates beneath the widget panel: