0

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)
Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
user11836845
  • 91
  • 2
  • 6
  • 1
    Does the CSV file exist on Heroku? You should check that the path to the file allows your Dash application to find the file in question. It would help if you [post the relevant code](https://stackoverflow.com/help/minimal-reproducible-example) as well. – Mihai Chelaru Jul 25 '19 at 14:29
  • The csv file is on my hard disk. How can I send it to heroku? – user11836845 Jul 25 '19 at 17:44
  • Is your CSV file version-controlled when you push to Heroku using git? What path are you using in your code to read the CSV file? You should probably be able to add it to version control and push it, or alternatively do something like what is suggested in [this Stack Overflow post](https://stackoverflow.com/questions/27761986/scp-file-from-local-to-heroku-server). – Mihai Chelaru Jul 25 '19 at 18:46
  • I deployed the app via heroku dashboard not the terminal so I did see anything like that – user11836845 Jul 25 '19 at 19:07
  • The app runs on Heroku, so it has no access to your local computer. You can't give it a path to a file from your computer and expect it to work the same way, especially if the file is not even present on Heroku. You need to find a way to upload the file to Heroku and then read it from there using the correct path, or alternatively host the file somewhere online and have the app go to the URL and read the CSV file from there. I'd recommend you [learn to use the CLI and deploy your app with Git instead](https://devcenter.heroku.com/articles/git). – Mihai Chelaru Jul 25 '19 at 20:03
  • Ok, I'll try that. I just had the idea of uploading the csv file on my github repository and read it with the url in my app.py – user11836845 Jul 25 '19 at 21:08
  • Ok, I'll try that. I just had the idea of uploading the csv file on my github repository and read it with the url in my app.py – user11836845 Jul 25 '19 at 21:08

3 Answers3

3

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()

user11836845
  • 91
  • 2
  • 6
0

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.

mybrave
  • 1,662
  • 3
  • 20
  • 37
0

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()
allenski
  • 1,652
  • 4
  • 23
  • 39