sdaza
1
I would like to load local data (csv file using pandas) on my dash app, but I get this error:
FileNotFoundError
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')
@server.route('/data/<path:path>')
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?
sdaza
3
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.
sdaza
5
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.
sdaza
7
Got it. It is working, the problem was I was using python mypath/app.py.
1 Like
Can someone show me a working example of how to read CSV file and plot a graph on local-server.
I am new to plotly and trying to understand how it works.
I have figured out how to use the pre-defined data in using this example but not sure how to read a csv file and do the same.