Hi,
I’m trying to make a plot that the plot width and x axis tick labels change with the values from two widget input: to_date and from_date. Now the x axis ticker labels and printed p.plot_width value change as the dates change, but the plot width does not update to the plot.
My code looks like below:
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(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]])
curdoc().add_root(page_layout)
Many thanks in advance!
Caroline