Reputation: 3
I have tried the below code to generate bokeh graphs for each of the element when the their respective check boxes are ticked. data is a df with columns like 'id', 'data_point', 'max', 'min' I am expecting a graph where if the data_point is empty or nonetype then the graph should not appear otherwise when the check boxes are ticked beside the id the graphs should appear for whichever id is being selected by the check box This should happen for every unique id. for one unique id the graph should look like below
data = df
if len(data) == 0:
logging.debug(" No data")
else:
req_hover = HoverTool(
tooltips=[
('data_point: ', '@data_point'),
('id: ', '@id')])
req_figure = figure(title='Graph', x_axis_label="Index", y_axis_label="id/data_point [ms]",
plot_width=800, plot_height=400, output_backend="webgl")
req_figure.add_tools(handover_hover)
id_values = data['id'].drop_duplicates()
column_view_data = data[
['id', 'tag', 'sw', 'name']].drop_duplicates().dropna()
column_view_data_source = ColumnDataSource(column_view_data)
data_table = DataTable(selectable='checkbox', source=column_view_data_source, columns=columns, width=1450,
height=400, css_classes=['blueTable'])
name_dict_req = {'name': [], 'legend': [], 'label': []}
logging.info('START OF DRAWINGS')
for ind, element in enumerate(elements):
d = []
for i, item in data.iterrows():
it_color = Turbo256[random.randint(0, 255)]
if element == item['id']:
if item['data_point'] is None or str(item['data_point']) == '[]':
item['data_point'] = '0'
else:
item['data_point'] = [float(x) for x in item['data_point'].strip('[').strip(']').split(',')]
raw_data_element_count = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20] # this is my x axis which will be 1 to 20
d.append({'id': id,
'number of raw data points': data_point_element_count,
'data_point': item['data_point']})
d_new = pd.DataFrame(d)
name_glyph_req = req_figure.line(x='number of raw data points',
y='data_point',
line_width=2,
legend_label=str(item['id']),
source=d_new,
color=it_color)
name_dict_req['name'].append(name_glyph_req)
name_dict_req['label'].append(str(item['id']))
logging.info('AFTER DRAWINGS LOOP')
for label in range(len(data.id.unique())):
name_dict_req['legend'].append(req_figure.legend.items[label])
initial_value = []
options = list(data.id.unique())
for i, name in enumerate(options):
options[i] = str(name)
for i in range(len(options)):
if name_dict_req['label'][i] in initial_value:
name_dict_req['name'][i].visible = True
name_dict_req['legend'][i].visible = True
else:
name_dict_req['name'][i].visible = False
name_dict_req['legend'][i].visible = False
#########################
callback_datatable = CustomJS(args=dict(source=column_view_data_source), code=callback_file_content_mq)
###################
column_view_data_source.selected.js_on_change('indices', callback_datatable)
req_figure.legend.location = "top_left"
req_figure.legend.click_policy = "hide"
logging.info('END DRAWINGS END SETUP')
Upvotes: 0
Views: 38
Reputation: 3
I think I did not provide a name dict in the customJS call in my code. So the issue was there that even if I click the checkboxes the graphs were not showing
Upvotes: 0