使用散景过滤小部件

问题描述

如何在不依赖ColumnDataSource(df)的情况下使用bokeh小部件过滤数据框并使用回调?

我的数据框列为:['Date','demand','Battery'],并希望按Battery进行过滤,但是ColumnDataSource需要一个具有独立列的数据框。我的数据名流在这三列中混合了所有内容

下面的示例代码仅对一列使用回调。我想通过电池的序列号更新和筛选所有可能的需求和日期。

df=pd.DataFrame()
df['x']= demand.loc[demand['Battery']==Battery,['Date']].to_numpy().flatten()
df['y']= demand.loc[demand['Battery']==Battery,['demand']].to_numpy().flatten()

source = ColumnDataSource(df)
bat= Battery
p=figure(x_axis_type='datetime',y_axis_label='Demand',plot_width=1000,plot_height=450)
p.line('x','y',source=source)
p.title.text='Battery' + '  ' + bat
p.title.align = 'center'

show(p)
    
# Create a dropdown Select widget: select    
select_menu= Select(title="Battery:",options=['5e6a62df','aasdfsds4330a'],value='5e6a62df')
callback= CustomJS(args={'source':source2},code=""" 
                   
        // print the selectd value of the select widget - 
        // this is printed in the browser console.
        // cb_obj is the callback object,in this case the select 
        // widget. cb_obj.value is the selected value.
        console.log(' changed selected option',cb_obj.value);

        // create a new variable for the data of the column data source
        // this is linked to the plot
        var data = source.data;

        // allocate the selected column to the field for the y values
        data['y'] = data[cb_obj.value];

        // register the change - this is required to process the change in 
        // the y values
        source.change.emit();
""") 

# Attach the update_plot callback to the 'value' property of select
select2.callback=callback
show(row(select2,p))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)