Search code examples
pandasgithubherokuerror-handlingplotly-dash

Deploying dash app on Heroku - Exception in worker process


I am trying to deploy my dash app with Heroku. I can deploy it on local host but it is not possible to deploy it with Heroku.

According to the logs (see below) it looks like there is something wrong with my Procfile.

This is the content of my Procfile:

web: gunicorn electricity_dashboard:server

Code of electricity_dashboard.py is the following:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.express as px

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']



url1 = 'url1.csv'
url2 = 'url2.csv'

df_hour = pd.read_csv(url1, index_col=0)
df_day = pd.read_csv(url2, index_col=0)



app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server

fig1 = px.bar(df_day, x="dayofweek", y="Consumption [Wh]")
fig2 = px.bar(df_hour, x="hour", y="Consumption [Wh]")


app.layout = html.Div(....)

if __name__ == '__main__':
    app.run_server()

Besides the Procfile which I suspect to be erroneous there is also an error regarding the pandas read_csv method. It seems like reading from my Github URL is not working.

pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 148, saw 2

These are the logs I got:

2022-02-06T21:20:54.046849+00:00 heroku[web.1]: Starting process with command `gunicorn electricity_dashboard:server`
2022-02-06T21:20:55.591730+00:00 app[web.1]: [2022-02-06 21:20:55 +0000] [4] [INFO] Starting gunicorn 20.1.0
2022-02-06T21:20:55.592181+00:00 app[web.1]: [2022-02-06 21:20:55 +0000] [4] [INFO] Listening at: http://0.0.0.0:28360 (4)
2022-02-06T21:20:55.592228+00:00 app[web.1]: [2022-02-06 21:20:55 +0000] [4] [INFO] Using worker: sync
2022-02-06T21:20:55.600422+00:00 app[web.1]: [2022-02-06 21:20:55 +0000] [9] [INFO] Booting worker with pid: 9
2022-02-06T21:20:55.671893+00:00 app[web.1]: [2022-02-06 21:20:55 +0000] [10] [INFO] Booting worker with pid: 10
2022-02-06T21:20:56.020715+00:00 heroku[web.1]: State changed from starting to up
2022-02-06T21:20:56.672424+00:00 app[web.1]: /app/electricity_dashboard.py:2: UserWarning:
2022-02-06T21:20:56.672445+00:00 app[web.1]: The dash_core_components package is deprecated. Please replace
2022-02-06T21:20:56.672446+00:00 app[web.1]: `import dash_core_components as dcc` with `from dash import dcc`
2022-02-06T21:20:56.672447+00:00 app[web.1]: import dash_core_components as dcc
2022-02-06T21:20:56.672586+00:00 app[web.1]: /app/electricity_dashboard.py:2: UserWarning:
2022-02-06T21:20:56.672586+00:00 app[web.1]: The dash_core_components package is deprecated. Please replace
2022-02-06T21:20:56.672587+00:00 app[web.1]: `import dash_core_components as dcc` with `from dash import dcc`
2022-02-06T21:20:56.672587+00:00 app[web.1]: import dash_core_components as dcc
2022-02-06T21:20:56.672980+00:00 app[web.1]: /app/electricity_dashboard.py:3: UserWarning:
2022-02-06T21:20:56.672982+00:00 app[web.1]: The dash_html_components package is deprecated. Please replace
2022-02-06T21:20:56.672982+00:00 app[web.1]: `import dash_html_components as html` with `from dash import html`
2022-02-06T21:20:56.672982+00:00 app[web.1]: import dash_html_components as html
2022-02-06T21:20:56.673497+00:00 app[web.1]: /app/electricity_dashboard.py:3: UserWarning:
2022-02-06T21:20:56.673498+00:00 app[web.1]: The dash_html_components package is deprecated. Please replace
2022-02-06T21:20:56.673499+00:00 app[web.1]: `import dash_html_components as html` with `from dash import html`
2022-02-06T21:20:56.673500+00:00 app[web.1]: import dash_html_components as html
2022-02-06T21:21:00.857089+00:00 app[web.1]: [2022-02-06 21:21:00 +0000] [9] [ERROR] Exception in worker process
2022-02-06T21:21:00.857103+00:00 app[web.1]: Traceback (most recent call last):
2022-02-06T21:21:00.857104+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-02-06T21:21:00.857104+00:00 app[web.1]: worker.init_process()
2022-02-06T21:21:00.857105+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
2022-02-06T21:21:00.857105+00:00 app[web.1]: self.load_wsgi()
2022-02-06T21:21:00.857105+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-02-06T21:21:00.857106+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2022-02-06T21:21:00.857107+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-02-06T21:21:00.857107+00:00 app[web.1]: self.callable = self.load()
2022-02-06T21:21:00.857107+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-02-06T21:21:00.857108+00:00 app[web.1]: return self.load_wsgiapp()
2022-02-06T21:21:00.857108+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-02-06T21:21:00.857108+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-02-06T21:21:00.857109+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
2022-02-06T21:21:00.857109+00:00 app[web.1]: mod = importlib.import_module(module)
2022-02-06T21:21:00.857109+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2022-02-06T21:21:00.857110+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-02-06T21:21:00.857110+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2022-02-06T21:21:00.857111+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2022-02-06T21:21:00.857111+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
2022-02-06T21:21:00.857111+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
2022-02-06T21:21:00.857112+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 850, in exec_module
2022-02-06T21:21:00.857112+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
2022-02-06T21:21:00.857112+00:00 app[web.1]: File "/app/electricity_dashboard.py", line 15, in <module>
2022-02-06T21:21:00.857113+00:00 app[web.1]: df_hour = pd.read_csv(url1, index_col=0)
2022-02-06T21:21:00.857113+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/util/_decorators.py", line 311, in wrapper
2022-02-06T21:21:00.857113+00:00 app[web.1]: return func(*args, **kwargs)
2022-02-06T21:21:00.857114+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 586, in read_csv
2022-02-06T21:21:00.857114+00:00 app[web.1]: return _read(filepath_or_buffer, kwds)
2022-02-06T21:21:00.857114+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 488, in _read
2022-02-06T21:21:00.857114+00:00 app[web.1]: return parser.read(nrows)
2022-02-06T21:21:00.857114+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 1047, in read
2022-02-06T21:21:00.857115+00:00 app[web.1]: index, columns, col_dict = self._engine.read(nrows)
2022-02-06T21:21:00.857115+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 224, in read
2022-02-06T21:21:00.857116+00:00 app[web.1]: chunks = self._reader.read_low_memory(nrows)
2022-02-06T21:21:00.857116+00:00 app[web.1]: File "pandas/_libs/parsers.pyx", line 801, in pandas._libs.parsers.TextReader.read_low_memory
2022-02-06T21:21:00.857116+00:00 app[web.1]: File "pandas/_libs/parsers.pyx", line 857, in pandas._libs.parsers.TextReader._read_rows
2022-02-06T21:21:00.857116+00:00 app[web.1]: File "pandas/_libs/parsers.pyx", line 843, in pandas._libs.parsers.TextReader._tokenize_rows
2022-02-06T21:21:00.857116+00:00 app[web.1]: File "pandas/_libs/parsers.pyx", line 1925, in pandas._libs.parsers.raise_parser_error
2022-02-06T21:21:00.857117+00:00 app[web.1]: pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 148, saw 2
2022-02-06T21:21:00.857117+00:00 app[web.1]:
2022-02-06T21:21:00.857243+00:00 app[web.1]: [2022-02-06 21:21:00 +0000] [9] [INFO] Worker exiting (pid: 9)
2022-02-06T21:21:00.858505+00:00 app[web.1]: [2022-02-06 21:21:00 +0000] [10] [ERROR] Exception in worker process
2022-02-06T21:21:00.858507+00:00 app[web.1]: Traceback (most recent call last):
2022-02-06T21:21:00.858507+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-02-06T21:21:00.858508+00:00 app[web.1]: worker.init_process()
2022-02-06T21:21:00.858509+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
2022-02-06T21:21:00.858509+00:00 app[web.1]: self.load_wsgi()
2022-02-06T21:21:00.858510+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-02-06T21:21:00.858510+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2022-02-06T21:21:00.858511+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-02-06T21:21:00.858511+00:00 app[web.1]: self.callable = self.load()
2022-02-06T21:21:00.858511+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-02-06T21:21:00.858512+00:00 app[web.1]: return self.load_wsgiapp()
2022-02-06T21:21:00.858512+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-02-06T21:21:00.858512+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-02-06T21:21:00.858513+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
2022-02-06T21:21:00.858513+00:00 app[web.1]: mod = importlib.import_module(module)
2022-02-06T21:21:00.858514+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2022-02-06T21:21:00.858514+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-02-06T21:21:00.858515+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2022-02-06T21:21:00.858515+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2022-02-06T21:21:00.858516+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
2022-02-06T21:21:00.858516+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
2022-02-06T21:21:00.858516+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 850, in exec_module
2022-02-06T21:21:00.858517+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
2022-02-06T21:21:00.858517+00:00 app[web.1]: File "/app/electricity_dashboard.py", line 15, in <module>
2022-02-06T21:21:00.858518+00:00 app[web.1]: df_hour = pd.read_csv(url1, index_col=0)
2022-02-06T21:21:00.858518+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/util/_decorators.py", line 311, in wrapper
2022-02-06T21:21:00.858518+00:00 app[web.1]: return func(*args, **kwargs)
2022-02-06T21:21:00.858519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 586, in read_csv
2022-02-06T21:21:00.858519+00:00 app[web.1]: return _read(filepath_or_buffer, kwds)
2022-02-06T21:21:00.858519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 488, in _read
2022-02-06T21:21:00.858520+00:00 app[web.1]: return parser.read(nrows)
2022-02-06T21:21:00.858530+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 1047, in read
2022-02-06T21:21:00.858530+00:00 app[web.1]: index, columns, col_dict = self._engine.read(nrows)
2022-02-06T21:21:00.858531+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 224, in read
2022-02-06T21:21:00.858532+00:00 app[web.1]: chunks = self._reader.read_low_memory(nrows)
2022-02-06T21:21:00.858532+00:00 app[web.1]: File "pandas/_libs/parsers.pyx", line 801, in pandas._libs.parsers.TextReader.read_low_memory
2022-02-06T21:21:00.858532+00:00 app[web.1]: File "pandas/_libs/parsers.pyx", line 857, in pandas._libs.parsers.TextReader._read_rows
2022-02-06T21:21:00.858533+00:00 app[web.1]: File "pandas/_libs/parsers.pyx", line 843, in pandas._libs.parsers.TextReader._tokenize_rows
2022-02-06T21:21:00.858533+00:00 app[web.1]: File "pandas/_libs/parsers.pyx", line 1925, in pandas._libs.parsers.raise_parser_error
2022-02-06T21:21:00.858534+00:00 app[web.1]: pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 148, saw 2
2022-02-06T21:21:00.858534+00:00 app[web.1]:
2022-02-06T21:21:00.858731+00:00 app[web.1]: [2022-02-06 21:21:00 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-02-06T21:21:01.340085+00:00 app[web.1]: [2022-02-06 21:21:01 +0000] [4] [WARNING] Worker with pid 10 was terminated due to signal 15
2022-02-06T21:21:01.433301+00:00 app[web.1]: [2022-02-06 21:21:01 +0000] [4] [INFO] Shutting down: Master
2022-02-06T21:21:01.433358+00:00 app[web.1]: [2022-02-06 21:21:01 +0000] [4] [INFO] Reason: Worker failed to boot.
2022-02-06T21:21:01.597094+00:00 heroku[web.1]: Process exited with status 3
2022-02-06T21:21:01.657248+00:00 heroku[web.1]: State changed from up to crashed

Thanks a lot in advance!


Solution

  • The problem was regarding the read_csv method. I did not specify the path to the data in my GitHub-repository correctly. Furthermore, in my case I also removed index_col=0. As stated in the answer to this question I had to use the raw content: How to read CSV file from GitHub using pandas

    This solved the problem and I could finally successfully deploy my dash app in Heroku.