简体   繁体   中英

bokeh server won't serve simple dateslider

The following code should define a bokeh app that consists of a single dateslider. If I save it as html ( serve=False ) it works as expected but the bokeh server returns a blank page. Any clues?

s = datetime.strptime('2019-01-01 14:00:00', '%Y-%m-%d %H:%M:%S')
e = datetime.strptime('2019-01-01 15:00:00', '%Y-%m-%d %H:%M:%S')
v = datetime.strptime('2019-01-01 14:01:00', '%Y-%m-%d %H:%M:%S')
st = timedelta(seconds=7)
slider = DateSlider(start=s, step=2, end=e, value=e, format='%Y-%m-%d %H:%M')
mylayout = column(children=[slider])

if serve:
    curdoc().add_root(mylayout)

else:
    fname = os.path.join(...)
    output_file(fname)
    save(mylayout)

Further questions:

  1. does the format string determine the lowest unit that changes when the slider is changed? (eg if I display seconds it will be seconds, if I display months it will be months)
  2. what does step do in this case? It doesn't seem to make any difference what value I choose, the behaviour is the same, it just slides smoothely.
  3. why is step required to be integral? I was expecting a timedelta value here.

All datetime values in Bokeh art typically in milliseconds, eg datetime axis values are milliseconds since epoch. Same in this case for intervals, eg here is an increment of 5 minutes:

from bokeh.models import DateSlider
from bokeh.io import curdoc
from bokeh.layouts import column
from datetime import datetime, timedelta

s = datetime.strptime('2019-01-01 14:00:00', '%Y-%m-%d %H:%M:%S')
e = datetime.strptime('2019-01-01 15:00:00', '%Y-%m-%d %H:%M:%S')
v = datetime.strptime('2019-01-01 14:01:00', '%Y-%m-%d %H:%M:%S')
st = timedelta(seconds=7)
slider = DateSlider(start=s, step=1000*60*5, end=e, value=e, format='%Y-%m-%d %H:%M')
mylayout = column(children=[slider])

curdoc().add_root(mylayout)

Having the step accept timedelta seems like a reasonable thing. Bokeh is huge project and many nice conveniences are not implemented simply because no one has ever pointed them out before. This would be a good issue to make aon GitHub, especially if you are interested in helping contribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM