In [1]:
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, TextInput, DatetimeTickFormatter, FactorRange
from bokeh.io import output_notebook, show
from bokeh.layouts import widgetbox, layout
output_notebook()
In [2]:
p = figure(plot_height=600)
# configure x axis
p.x_range = FactorRange()
p.xaxis[0].formatter = DatetimeTickFormatter(formats=dict(
hours=["%Y-%m-%d"],
days=["%Y-%m-%d"],
months=["%Y-%m-%d"],
years=["%Y-%m-%d"],
))
source = ColumnDataSource(data=dict(x=[], y=[]))
r = p.circle(x='x', y='y', source=source)
from_date = TextInput(value='2016-03-01',
title='Please enter the starting date in the format of yyyy-mm-dd')
to_date = TextInput(value='2016-04-30',
title='Please enter the ending date in the format of yyyy-mm-dd')
def update_plot(attr, old, new):
d_range = pd.date_range(from_date.value.strip(), to_date.value.strip()).strftime('%Y-%m-%d')
p.plot_width = 25 + len(d_range) * 65 + 25
print(p.plot_width)
p.x_range.factors = d_range.tolist()
p.xaxis[0].ticker = CategoricalTicker(tags=d_range.tolist())
p.xgrid[0].ticker = CategoricalTicker(tags=d_range.tolist())
ds2.data = dict(...)
from_date.on_change('value', update_plot)
to_date.on_change('value', update_plot)
controls = [from_date, to_date]
w_box = widgetbox(controls, width=200, sizing_mode='fixed')
# page_layout = row(w_box, p)
page_layout = layout(children=[[w_box, p]])
In [3]:
show(page_layout)
Out[3]:
In [ ]: