title: Internal Server Error: Dash on Flask on AWS Elastic Beanstalk
body: <p><strong>NB:</strong> Dash is a python package used to build dashboards by plotly (website <a href="https://plot.ly/products/dash/" rel="noreferrer">here</a>). Flask is a python package used to build python web frameworks (website <a href="http://flask.pocoo.org/" rel="noreferrer">here</a> and AWS tutorial <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html/" rel="noreferrer">here</a>). I am using python 3.6 and all package versions can be seen below in requirements.txt</p>
  <p><strong>Problem:</strong> I get an error when launching my Dash app onto my AWS EB.</p>
  <p>When I run locally on 127.0.0.1:8050 my dash works. However when I <code>$ eb deploy</code> I get this on my AWS EB URL:</p>
  <blockquote>
  <p><b>Internal Server Error</b></p>
  <p>The server encountered an internal error or misconfiguration and was unable to complete your request.</p>
  <p>Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.</p>
  <p>More information about this error may be available in the server error log.</p>
  </blockquote>
  <p>My file structure is as so (where <code>eb-flask</code> is my flask directory):</p>
  <pre><code>~/AWS/servers/flask-s
    |-- eb-virt                   }
    |    |-- bin                  }
    |    |-- include              } virtualenv files etc
    |    |-- lib                  }
    |    `-- pip-selfcheck.json   }
    |
    |-- eb-flask              &lt;--- where I ran eb init
    |    |-- application.py
    |    |-- requirements.txt
    |    |-- .gitignore
    |    |-- .elasticbeanstalk
    `         `-- config.yml
  </code></pre>
  <p>When using <code>$ eb config</code>:</p>
  <pre><code>aws:elasticbeanstalk:container:python:
    NumProcesses: '1'
    NumThreads: '15'
    StaticFiles: /static/=static/
    WSGIPath: application.py
  </code></pre>
  <p>My application.py code is pretty much lifted from <a href="https://dash.plot.ly/deployment" rel="noreferrer">https://dash.plot.ly/deployment</a> as test.</p>
  <pre><code>import flask
  import os
  import dash
  import dash_core_components as dcc
  import dash_html_components as html
  
  #app = dash.Dash(_name_)
  #server = app.server
  
  server = flask.Flask(_name_)
  application = dash.Dash(_name_, server=server)
  
  application.css.append_css({&quot;external_url&quot;: &quot;https://codepen.io/chriddyp/pen/bWLwgP.css&quot;})
  
  application.layout = html.Div([
      html.H2('Hello World'),
      dcc.Dropdown(
          id='dropdown',
          options=[{'label': i, 'value': i} for i in ['LA', 'NYC', 'MTL']],
          value='LA'
      ),
      html.Div(id='display-value')
  ])
  
  @application.callback(dash.dependencies.Output('display-value', 'children'),
                [dash.dependencies.Input('dropdown', 'value')])
  def display_value(value):
  return 'You have selected &quot;{}&quot;'.format(value)
  
  if _name_ == '_main_':
      application.run_server(debug=True)
  #app.run_server()
  </code></pre>
  <p>requirements.txt is obviously pip freeze. At this point it is just the required packages for flask, dash and plotly:</p>
  <pre><code>certifi==2018.4.16
  chardet==3.0.4
  click==6.7
  dash==0.21.1
  dash-core-components==0.22.1
  dash-html-components==0.10.1
  dash-renderer==0.12.1
  decorator==4.3.0
  Flask==1.0.2
  Flask-Compress==1.4.0
  gunicorn==19.8.1
  idna==2.6
  ipython-genutils==0.2.0
  itsdangerous==0.24
  Jinja2==2.10
  jsonschema==2.6.0
  jupyter-core==4.4.0
  MarkupSafe==1.0
  nbformat==4.4.0
  numpy==1.14.3
  pandas==0.23.0
  plotly==2.6.0
  python-dateutil==2.7.3
  pytz==2018.4
  requests==2.18.4
  six==1.11.0
  traitlets==4.3.2
  urllib3==1.22
  Werkzeug==0.14.1
  </code></pre>
  <p>Something is obviously wrong server-side. When I run <code>(eb-virt) $ python application.py</code> I can access the site locally. I get this response from a HTTP GET:</p>
  <pre><code>(eb-virt): eb-flask $ python application.py 
   * Serving Flask app &quot;application&quot; (lazy loading)
   * Environment: production
     WARNING: Do not use the development server in a production environment.
     Use a production WSGI server instead.
   * Debug mode: on
   * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
   * Restarting with stat
   * Debugger is active!
   * Debugger PIN: 190-847-760
  127.0.0.1 - - [22/May/2018 18:41:30] &quot;GET / HTTP/1.1&quot; 200 -
  127.0.0.1 - - [22/May/2018 18:41:31] &quot;GET /_dash-layout HTTP/1.1&quot; 200 -
  127.0.0.1 - - [22/May/2018 18:41:31] &quot;GET /_dash-dependencies HTTP/1.1&quot; 200 -
  127.0.0.1 - - [22/May/2018 18:41:31] &quot;POST /_dash-update-component HTTP/1.1&quot; 200 -
  127.0.0.1 - - [22/May/2018 18:41:31] &quot;GET /favicon.ico HTTP/1.1&quot; 200 -
  </code></pre>
  <p>Yet when I <code>$ eb deploy</code> I get the aforementioned Internal Server Error. I appreciate any help.</p>
  <p>When I <a href="https://stackoverflow.com/questions/32722143/flask-application-traceback-doesnt-show-up-in-server-log">enable logging</a>, I get <code>application.logger.addHandler(handler) AttributeError: 'Dash' object has no attribute 'logger'</code> locally. On deploying, there are no errors appended to the log file, it just remains blank.</p>