I am trying to make an interactive graph using Altair. However, when I build the function, there was no error message but there is nothing plot as well.
Below is my code:
date_range_slider = pn.widgets.DateRangeSlider(name = 'Date',
start = df['date'].min(), end = df['date'].max())
@pn.depends(c1.param.value, c2.param.value, date_range_slider.param.value)
def plots(c1, c2, date_range):
#Data selection
df = raw
df['date'] = pd.to_datetime(df['date'], dayfirst = True)
df['daily_cases'] = df.groupby(['country'])['cases'].diff(1).fillna(df['cases'])
df = df.loc[(df['date'] >= date_range_slider.value[0]) & (df['date'] <= date_range_slider.value[1])]
#Plotting
graph = alt.Chart(df).mark_line().encode(alt.X('cases', scale = alt.Scale(type = 'log')),
alt.Y('daily_cases', scale = alt.Scale(type = 'log'))).transform_filter(
(datum.symbol == c1) & (datum.symbol == c2))
return graph
My c1 and c2 are name of country contained in lists. My data range is pandas datetime in my dataframe.
I also enable display function in jupyter notebook as:
alt.renderers.enable('default')
pn.extension('vega')
alt.data_transformers.disable_max_rows()
However, when I run
dashboard = pn.Row(pn.Column(c1, c2, date_range_slider), plots)
dashboard.servable()
There is only a blank graph but I use date range and country filler.
Any suggestion? Thank you!