DataTIME slider or picker callbacks to update plots

I am currently building an interactive gmap of renewable energy projects with dropdowns etc that update the map with different types of data. The next major hurdle is adding a dateTIME slider that will change data displayed on the plot (i’m dealing with hourly data over several years). I’ve seen many examples working with years/months as strings/integers but almost nothing related to datetime - example being update the plot to show 2019-12-01 16:00:00 to 2020-03-19 10:00:00.

If anyone has cracked datetime driven updates of a plot, or map, please share. I’m hoping this will make a showcase of Bokeh and its potential for the renewables industry.

I’ll post my progress, if any, here as I go.

Thanks in advance

@sesoko88 there is not a dedicated widget for this, only for date values. However, I think it can be accomplished:

  • The underlying units of datetime in Bokeh are “milliseconds since epoch” so you would create a regular Slider with start, end etc configured in milliseconds.
  • Sliders can accept a TickFormatter as their format, so you can use a DatetimeTickFormatter to display the slider values as formatted datetimes instead of milliseconds.

This worked for me:

from bokeh.models import Slider
from bokeh.models.formatters import DatetimeTickFormatter

Slider = Slider(title="Slider ", start=dt(2016, 1, 1, 0).timestamp()*1000, end=dt(2020, 1, 1, 0).timestamp()*1000, value=dt(2016, 1, 1).timestamp()*1000, step=60000, orientation='vertical', format=DatetimeTickFormatter(years="'%Y-%m-%d %H:%M"))

If you want to select a Range use RangeSlider instead of Slider

Josu Catalina.

Thank you @Bryan and @Josu_Catalina for your suggestions, hoping to find time in the next couple of weeks to give these a go. Perhaps other users also have different approaches they’ll share as it would help to gather some dateTIME documentation/examples for Bokeh - especially considering the capabilities of datashader as this is golden for large timeseries datasets.

I only discovered Bokeh a couple of months ago and wish I had sooner!