✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Selecting country by dropdown menu


I’m just getting to grips with dash and trying to recreate some graphs I made with plotly.

I have a master.csv stored in a dataframe with info for many countries. I want to use a dropdown to select country and graph variables.

Here is my code:

import requests
import requests_cache
import time

import json

from functools import reduce

import pandas as pd
import numpy as np
from pandas import Series, DataFrame, json_normalize

from datetime import datetime

import plotly.offline as pyo
import plotly.graph_objs as go

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

# Launch the application:
app = dash.Dash()

# Read csv to DataFrame call and store the response.
df = pd.read_csv('data\master.csv')


country_options = []
for country in df['Country'].unique():

#Create a Div to hold graph
app.layout = html.Div([

              [Input('country-picker', 'value')])

def update_country(selected_country):
    filtered_df = df[df['Country'] == selected_country]

    traces = []
    #for country in filtered_df.unique():
        y=filtered_df['New Cases']

    return {
        'data': traces,
        'layout': go.Layout(
            xaxis={ 'title': 'Date'},
            yaxis={'title': 'New Cases'},

if __name__ == '__main__':

I’m not quite sure how to go about selecting info in the function to select county. I am summing all of the values instead of creating a unique value for each date. Is there another way to go about this?

Here is a readout of my df headers:
New Cases
SMA_7 New
Pct Ch New