I have a Bokeh server application that is using a ColumnDataSource and two DatePicker widgets for a vbar_stack plot. I want to filter the data being shown on the plot using the range from the DatePickers' values. The CDS was created by the following dataframe (the index consists of datetime values):
Device1 Device2 Device3
2020-10-24 H-m-S 0 1 2
2020-10-25 H-m-S 1 0 1
2020-10-25 H-m-S 2 0 0
2020-10-25 H-m-S 0 2 0
I want to filter the data by a specific date range, so I made another dataframe consisting of only the rows within the date range we found from the parameters set by the DatePickers (for this example, the start range Datepicker’s value is 10/25/2020, so the 10/24 row is filtered out):
Device1 Device2 Device3
2020-10-25 H-m-S 1 0 1
2020-10-25 H-m-S 2 0 0
2020-10-25 H-m-S 0 2 0
Now, I want to pass this to the plot without affecting the original dataframe. For this I thought to use
Source.data = ColumnDataSource.from_df(data.loc[start:end])
.
However, the plot just goes blank and doesn’t update. Is there any specific way I should pass this data to the CDS already in use by the plot? I can’t wrap my head around the specific format. Or is there a different approach to filtering this data that I should try?
I managed to figure it out -- in order to pass the data from that dataframe into my existing data source, I had to make a new CDS and update it to the original, like so:
new_source = ColumnDataSource(selected)
source.data.update(new_source.data)
The plot is updating as it should now!