Dash: load local data using pandas


I would like to load local data (csv file using pandas) on my dash app, but I get this error:


My data are in the folder ‘data’. This doesn’t work:

server = flask.Flask('congress')
app = dash.Dash('congress', server=server, csrf_protect=False)
server.secret_key = os.environ.get('secret_key', 'secret')

pol = pd.read_csv('data/tweets_pol.csv')

def serve_static(path):
    root_dir = os.getcwd()
    return flask.send_from_directory(os.path.join(root_dir, 'data'), path)

Any suggestions?


I don’t quite follow. Why are using the server.route? And which line is failing, the pd.read_csv line or the flask.send_from_directory line?


I guess pd.read_csv is failing, but I am not completely sure.

FileNotFoundError: File b'/data/tweets_pol.csv' does not exist

Do you have an example that works with data from local files?

Thank you!


Are you on windows? If so, you’ll probably need to use windows path names in pd.read_csv. On my mac, pd.read_csv('data/my-datafile.csv') works for me.


I am using a mac. Are you using any flask server command?


No, you shouldn’t need to use this. Here is a concrete example from one of the demo apps: https://github.com/plotly/dash-drug-discovery-demo/blob/master/app.py#L13.


Got it. It is working, the problem was I was using python mypath/app.py.