I thought I found a concrete example that I could leverage here, but the same logic is not working for me, unfortunately.
I have two questions:
Is what I'm attempting to do even possible: send a dynamic scatter plot in a html document that allows you to control what is plotted on the x & y axes. I've succeeded with static plots, but haven't cracked dynamic plots yet.
Where is my code going wrong (see below?)
Here are the relevant pieces of code (in order. I have a dataframe that I've converted into "source" using ColumnDataSource.
I create an initial plot (note, at this point, there are no columns called 'x' and 'y'. I create those in the callback function later) :
plot.circle('x', 'y',
source=source,
color={'field': 'Picker',
'transform': mapper},
legend='Picker')
I create two dropdown menus (note that the options in each correspond to the columns from "source" I'd want people to be able to choose from)
x_menu=Select(options=['Box Office', 'Difference', 'Price Paid'],
value='Box Office',
title='What do you want to put on the x axis')
y_menu=Select(options=['Metacritic', 'Rotten Tomatoes'],
value='Metacritic',
title='What do you want to put on the y axis')
I create the callback:
callback = CustomJS (args=dict(source=source), code="""
console.log('changed selected option', cb_obj.value)
var data=source.data
data['x']=data[cb_obj.value]
data['y']=data[cb_obj.value]
source.change.emit();
""")
I assign the callbacks to the dropdown menus:
x_menu.callback = callback
y_menu.callback = callback
And then I try to show the plot:
show(row(widgetbox(x_menu, y_menu), plot))
But it returns the below error:
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: x, y [renderer: GlyphRenderer(id='df96b108-e2e4-4b8c-b0c6-12df40b4205d', ...)]
Any help is very much appreciated. Thank you!