Skip to content

Instantly share code, notes, and snippets.

@Hephaestus12
Created August 29, 2020 12:46
Show Gist options
  • Save Hephaestus12/f5b632b434925483c1f1f505de71143f to your computer and use it in GitHub Desktop.
Save Hephaestus12/f5b632b434925483c1f1f505de71143f to your computer and use it in GitHub Desktop.
@app.callback(
Output("count_graph", "figure"),
[
Input("model_selector", "value"),
Input("country_names", "value"),
Input("year_selector", "value"),
],
)
def make_histogram(model, countries, years):
cases = {}
for year in years:
for country in countries:
for index, row in df[country].iterrows():
if(row['week'][:4] == year):
if(row['date'] in cases):
cases[row['date']] += row['estimate_'+model]
else:
cases[row['date']] = row['estimate_'+model]
weeks = []
estimates = []
for key in cases:
weeks.append(datetime.strptime(key, '%Y-%m-%d'))
estimates.append(cases[key])
estimates = [x for _, x in sorted(zip(weeks, estimates))]
weeks.sort()
dff = {'week': weeks, 'cases': estimates}
fig = px.bar(dff, x='week', y='cases',
hover_data=['cases'], color='cases',
labels={'cases': 'number of Influenza cases', 'week': 'Date'},
title='Cases over the years',)
return fig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment