In my app I have several graphs based on the same dataframe. I need to filter that df according to date and when I filter, all my graphs must be rendered with filtered data. My code is:
date_range = pn.widgets.DateRangeSlider(name='Date Range', start=data["date"].iloc[0], end=data["date"].iloc[-1], step=1*1*1)
# Trend Graph for Dampers
@pn.depends(date_range)
def update_df(x):
df_filtered = data[(data['date'] > date_range.value[0]) & (data['date'] < date_range.value[1])]
return df_filtered
get_dataframe = pn.bind(update_df, date_range)
filtered_df = get_dataframe()
# Trend Graph for dT
def plot_scatter1( selected_col_for_x, selected_col_for_y):
tagname_in_db_forX = definition_dict[selected_col_for_x]
tagname_in_db_forY = definition_dict[selected_col_for_y]
hover = HoverTool(
tooltips=[
(selected_col_for_x,"$x{0.0}"),
(selected_col_for_y,"$y{0.0}")
],
formatters={
selected_col_for_x: "printf",
selected_col_for_y: "printf"
},
mode='vline'
)
graph = filtered_df.hvplot(x = tagname_in_db_forX, y=tagname_in_db_forY, xlabel=selected_col_for_x, ylabel=selected_col_for_y, kind="scatter", shared_axes=False, line_width=2, tools=[hover])
return graph
# Trend Graph for dT
def plot_trend4( selected_col):
tagname_in_db = definition_dict[selected_col]
hover = HoverTool(
tooltips=[
('cihaz_ismi', cihaz_ismi),
('Zaman', "@date{%Y-%m-%d %H:%M}"),
(selected_col,"$y{0.0}")
],
formatters={
"@date": "datetime",
selected_col: "printf"
},
mode='vline'
)
graph4 = filtered_df.hvplot(x = 'date', by='_measurement', y=tagname_in_db, xlabel='Zaman', ylabel='', shared_axes=False, line_width=2, tools=[hover])
return graph4
graph4=plot_trend4('Sisteme Kazandırılan Fark Sıcaklık')
graph5=plot_trend4('Fan Frekansı')
graph6=plot_trend4('Toplam Debi')
scatter1=pn.pane.HoloViews(plot_scatter1('Toplam Debi','Sisteme Kazandırılan Fark Sıcaklık'), backend='bokeh', sizing_mode="stretch_width", height=300)
This code only works at startup , later on, it does not reflect any update on graphs. And date_range slider acts a bit strage too. It moves both handles together. So I need help here. Thanks in advance.