I have a plot defined like so where fetch_data(x,y)
returns a dict from a dataframe from the specified columns as well as the species names.
source = ColumnDataSource(fetch_data('body_wt','gestation'))
p = figure(x_axis_type='log',y_axis_type='log',tooltips=[('species', '@species'),('xs', '@xs'),('ys', '@ys')],title='DVA: Mammal Sleep Data Inspector')
p.xaxis.axis_label = 'body_wt'
p.yaxis.axis_label = 'gestation'
p.circle('xs', 'ys', source=source)
show(p)
Here, I want to have a callback function thatâs supposed to updates the ColumnDataSource and axis labels based on the Select
widgets.
def callback(select_xaxis:str,select_yaxis:str):
source = ColumnDataSource(fetch_data(select_xaxis,select_yaxis))
p.xaxis.axis_label = select_xaxis
p.yaxis.axis_label = select_yaxis
pass
select_xaxis = Select(title='X-Axis Variable',
value='body_wt',
options=['predation','exposure','danger','body_wt','brain_wt','non_dreaming','dreaming','total_sleep','life_span','gestation'])
select_yaxis = Select(title='Y-Axis Variable',
value='gestation',
options=['predation','exposure','danger','body_wt','brain_wt','non_dreaming','dreaming','total_sleep','life_span','gestation'])
select_xaxis.js_on_change('value',CustomJS(args=dict(source=callback(select_xaxis.value,select_yaxis.value))))
select_yaxis.js_on_change('value',CustomJS(args=dict(source=callback(select_xaxis.value,select_yaxis.value))))
lt = layout(column(select_xaxis,select_yaxis),p)
show(lt)
How do I properly implement the Select
widgets and connect them to the callback function? (Assuming I defined the callback function correctly)