Hi, could anyone have a look at my code and give some hints what’s wrong?
Everything is visible but with no interactions. I’d like to use numpy so the code takes lists as inputs only.
import numpy as np
from bokeh.io import curdoc, show, output_notebook
from bokeh.layouts import row, column
from bokeh.models import ColumnDataSource, Select, Div, Title, WidgetBox
from bokeh.plotting import figure
feature_list = ['name', 'age', 'sex', 'salary']
var = [[1,2,3,4,5,6,7,8],
[3,5,2,1,4,4,5,3],
[4,3,6,4,3,3,5,2],
[3,3,2,1,6,1,1,3]]
def map_feature(name, value):
return {i: y for i, y in zip(name, value)}
data = map_feature(feature_list, var)
source = ColumnDataSource(data=data)
def viz_plot():
x = list(data.keys())[0]
y = list(data.keys())[-1]
vp = figure(plot_width = 300, plot_height = 300)
vp.circle(x = x, y = y, source = source)
vp.xaxis.axis_label = x
vp.yaxis.axis_label = y
return vp
select_x_axis = Select(title = 'X-axis',
value = feature_list[0],
options = feature_list)
select_y_axis = Select(title = 'Y-Axis',
value = feature_list[-1],
options = feature_list)
def update_data(attr, old, new):
x_value = select_x_axis.value
y_value = select_y_axis.value
x = {k : v for k, v in data.items() if k == x_value}
y = {k : v for k, v in data.items() if k == y_value}
source.data = {**x, **y}
for selector in [select_x_axis, select_y_axis]:
selector.on_change('value', update_data)
menu = WidgetBox(select_x_axis, select_y_axis, width=200)
layout = row(menu, viz_plot(), width=800)
#show(layout)
curdoc().add_root(layout)
curdoc().title = "Menu"