Is it possible to change the names of the series displayed on the plot dynamically (depending on the current selection of the user)? This is my attempt, but the legend doesn't change.
df['y'] = df.iloc[:, 2].values
df['y2'] = df.iloc[:, 3].values
TITLE = 'test'
output_file(TITLE + '.html')
p = figure(x_axis_type='datetime', title=TITLE)
source = ColumnDataSource(df)
line1 = p.line(x='Date', y='y', source=source, color="blue", legend_label='Line 1')
line2 = p.line(x='Date', y='y2', source=source, color="red", legend_label='Line 2')
columns_without_y = [col for col in df.columns[1:] if col not in ['y', 'y2']]
ys1 = Select(title='Select Column 1:', value=df.columns[1], options=columns_without_y)
ys2 = Select(title='Select Column 2:', value=df.columns[2], options=columns_without_y)
callback = CustomJS(args=dict(source=source, sel1=ys1, sel2=ys2, line1=line1, line2=line2), code="""
const data = source.data;
const column1 = sel1.value;
const column2 = sel2.value;
data['y'] = data[column1];
data['y2'] = data[column2];
source.change.emit();
line1.glyph.legend_label = column1;
line2.glyph.legend_label = column2;
""")
ys1.js_on_change('value', callback)
ys2.js_on_change('value', callback)
controls = column(ys1, ys2)
layout = row(controls, p)
show(layout)