user11836845
user11836845

Reputation: 101

Dash app deployed on Heroku cannot read CSV file

I'm trying to use Heroku to deploy my Dash app, which is supposed to read data from a local CSV file. The deployment was successful, but if I open the URL of the app, it gives me an Application Error.

I have checked the Heroku logs and I found a FileNotFoundError which tells me the CSV file from which the app reads the data does not exist, but it works if I run the app locally. In fact, the CSV file exists in my directory, so I want to know if there's another way to go about this.

EDIT: Actually, this is how my app.py code starts. The FileNotFoundError points to the part where I read the CSV file with pandas. How can I get my app to read the CSV file?

import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table as tablefrom

from dash.dependencies import Input, Output
import plotly as py
import plotly.graph_objs as go
import numpy as np
import pandas as pd

filepath='C:\\Users\\DELL\\Desktop\\EDUCATE\\DATA CSV\\crop_prod_estimates_GH.csv' 

data=pd.read_csv(filepath,sep=',',thousands=',')
data.dropna(inplace=True)

data[['REGION','DISTRICT','CROP']]=data[['REGION','DISTRICT','CROP']].astype('category')
data.CROP=data.CROP.str.strip()
data.drop(data.columns[0],axis=1,inplace=True)

Upvotes: 0

Views: 4119

Answers (3)

Gildas Nouebissi
Gildas Nouebissi

Reputation: 1

Upload your csv file on cloudinary:

urlfile = 'https://res.cloudinary.com/hmmpyq8rf/raw/upload/v1604671300/localisationDigixpress_n8s98k.csv'

df = pd.read_csv(urlfile,sep=",")

df.head()

Upvotes: 0

ravinder kumar
ravinder kumar

Reputation: 1

You can store the csv file at the same location where your app.py exists.

Change from:

filepath='C:\\Users\\DELL\\Desktop\\EDUCATE\\DATA CSV\\crop_prod_estimates_GH.csv' 

To:

filepath='crop_prod_estimates_GH.csv' 

It should work.

Upvotes: 0

user11836845
user11836845

Reputation: 101

Solved it!!!!!!!!!

I uploaded my csv data file on my github repository and had the app.py read data from it.like:

url = 'https://raw.githubusercontent.com/your_account_name/repository_name/master/file.csv'

df = pd.read_csv(url,sep=",")

df.head()

Upvotes: 4

Related Questions