Hey everyone-
I posted this over at Stack Overflow as well here, but no luck yet.
I have a very similar problem to this post. It looked like the user came up with a clunky workaround, but it utilized bokeh server and I’d love to come up with a solution that would output the dynamic chart into a html file. So, my assumption is I need to figure something out via CustomJS callbacks.
Long story short, I’d love to have a plot and a dropdown. When you change the dropdown, everything stays the same, but there would be different stats fed to the tooltips. I wrote some sample code that should paint a pretty clear picture of what I’m trying to do. You can access it at the Stack Overflow post. I’ll also attached the code to this post, and I’ll past the text it at the very bottom.
Anyone have any ideas?
Here’s the code:
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.models import CustomJS, ColumnDataSource, HoverTool, ColumnDataSource, Select
from bokeh.layouts import row
#Create a dataframe with x and y coordinates and 4 different statistics
df = pd.DataFrame({
'x':[1,2,3],
'y':[1,2,3],
'stat1':[1,2,3],
'stat2':[4,5,6],
'stat3':[7,8,9],
'stat4':[10,11,12],
'stat5':[13,14,15]
})
#Create Bokeh's ColumnDataSource
source=ColumnDataSource(data=df)
#Create the different options for the Hovertool tooltips. Note the dynamic number of stats
option1=[('Stat1','@stat1'),
('Stat2','@stat2')]
option2=[('Stat3','@stat3'),
('Stat4','@stat4'),
('Stat5','@stat5')]
#Set the default option for the Hovertool tooltips
hover=HoverTool(tooltips=option1)
#Create the figure
plot = figure(tools=[hover])
plot.circle('x', 'y', source=source)
#Create the callback that will update the tooltips
callback = CustomJS (args=dict(tt=plot.hover), code= """
if (cb_obj.value='Stat Set 1') {
tt.tooltips=option1
} else {
tt.tooltips=option2
}
""")
#Create a dropdown menu that allows you to change which set of stats will populate the tooltips
stat_select=Select(options=['Stat Set 1', 'Stat Set 2'],
value='Stat Set 1',
title='What stats set do you want to see when you hover?', callback=callback)
show(row(stat_select,plot))
Mapper.ipynb (13.8 KB)