[,请问如何通过用户选择小部件更新滑块的最小值和最大值,即index_min和index_max?例如,当选择u1时,滑块的最小值和最大值应为2586和2836。
import pandas as pd
from bokeh.layouts import column, layout
from bokeh.models import ColumnDataSource, Select, Slider
from bokeh.io import curdoc
from bokeh.plotting import figure
df = pd.DataFrame({'Time': [2586, 2836, 2986, 3269, 3702],
'X': [120, 210, 80, 98, 40],
'Y': [230, 40, 33, 122, 10],
'User': ['u1', 'u1', 'u2', 'u2', 'u2'],
'img': ['tree1.png', 'tree2.jpg', 'tree3.jpg', 'tree4.jpg','tree5.jpg']})
source = ColumnDataSource(data=dict(time=[], x=[], y=[], user=[], img=[]))
options = sorted(set(df['User']))
user_options = ['Please select ...'] + options
users = Select(title="User:", value=user_options[0], options=user_options)
index_min = df['Time'].min()
index_max = df['Time'].max()
index = Slider(start=index_min, end=index_max, value=index_max , step=1, title="Time Index")
def select_user():
user_val = users.value
selected = df[(df.Time <= index.value)]
if (user_val != ""):
selected = selected[selected.User.str.contains(user_val)==True]
return selected
def update():
dfnew = select_user()
source.data = dict(time=dfnew['Time'], x=dfnew['X'], y=dfnew['Y'], user=dfnew['User'], img=dfnew['img'])
controls = [users, index]
for control in controls:
control.on_change('value', lambda attr, old, new: update())
p = figure(plot_width = 600, plot_height = 600)
p.circle(x="x", y="y", source=source, legend='user')
update() # initial load of the data
l = layout(column(users, index, p))
curdoc().add_root(l)
[,请问如何通过用户选择小部件更新滑块的最小值和最大值,即index_min和index_max?例如,当选择u1时,滑块的最小值和最大值应为2586 ...
这就是我的做法。