Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

[Solved] Fyi: Internal Service Error on deploy: TypeError: 'Dash' object is not callable

FYI that on deploy I’m seeing Internal Service Error and the logs show “TypeError: ‘Dash’ object is not callable”.

Have my Procfile go through gunicorn to a wsgi using WhiteNoise and then a point to the Dash app.py.

Procfile

web: gunicorn wsgi:application --log-file -

wsgi.py

from whitenoise import WhiteNoise

from app import app

application = WhiteNoise(app)
application.add_files(‘static/’, prefix=‘static/’)

app.py

import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html

from pandas_datareader import data as web
from datetime import datetime as dt

app = dash.Dash(‘Hello World’)

app.layout = html.Div([
dcc.Dropdown(
id=‘my-dropdown’,
options=[
{‘label’: ‘Coke’, ‘value’: ‘COKE’},
{‘label’: ‘Tesla’, ‘value’: ‘TSLA’},
{‘label’: ‘Apple’, ‘value’: ‘AAPL’}
],
value=‘COKE’
),
dcc.Graph(id=‘my-graph’)
], style={‘width’: ‘500’})

@app.callback(Output(‘my-graph’, ‘figure’), [Input(‘my-dropdown’, ‘value’)])
def update_graph(selected_dropdown_value):
df = web.DataReader(
selected_dropdown_value,
‘google’,
dt(2017, 1, 1),
dt.now()
)
return {
‘data’: [{
‘x’: df.index,
‘y’: df.Close
}],
‘layout’: {‘margin’: {‘l’: 40, ‘r’: 0, ‘t’: 20, ‘b’: 30}}
}

app.css.append_css({‘external_url’: ‘https://codepen.io/chriddyp/pen/bWLwgP.css’})

if name == ‘main’:
app.run_server(debug=True)

Chad

Have it half-way fixed by figuring out that I needed to add a separate server.py file…

Procfile
web: gunicorn app:server --log-file -

app.py

import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html

from pandas_datareader import data as web
from datetime import datetime as dt

from server import app, server

app.layout = html.Div([
dcc.Dropdown(
id=‘my-dropdown’,
options=[
{‘label’: ‘Coke’, ‘value’: ‘COKE’},
{‘label’: ‘Tesla’, ‘value’: ‘TSLA’},
{‘label’: ‘Apple’, ‘value’: ‘AAPL’}
],
value=‘COKE’
),
dcc.Graph(id=‘my-graph’)
], style={‘width’: ‘500’})

@app.callback(Output(‘my-graph’, ‘figure’), [Input(‘my-dropdown’, ‘value’)])
def update_graph(selected_dropdown_value):
df = web.DataReader(
selected_dropdown_value,
‘google’,
dt(2017, 1, 1),
dt.now()
)
return {
‘data’: [{
‘x’: df.index,
‘y’: df.Close
}],
‘layout’: {‘margin’: {‘l’: 40, ‘r’: 0, ‘t’: 20, ‘b’: 30}}
}

app.css.append_css({‘external_url’: ‘https://codepen.io/chriddyp/pen/bWLwgP.css’})

if name == ‘main’:
app.run_server(debug=True)

server.py

import dash
from dash import Dash
import dash_html_components as html
import dash_core_components as dcc
from flask import Flask, request
import json
import plotly.graph_objs as go
import os

server = Flask(name)
server.secret_key = os.environ.get(‘secret_key’, ‘secret’)
app = Dash(name, server=server, url_base_pathname=’/dash/’, csrf_protect=False)

app.config.supress_callback_exceptions = True

2 Likes

Finally got this test to load and run on Heroku by changing the above to :

app = Dash(name, server=server)

So, with that edit to server.py and the Procfile and app.py from above this simple test is now going on Heroku.

More testing to follow. Primary next interest will be in setting up login/authorization control.

Cheers.

2 Likes

that’s great for me , I face the same problem and I follow the way and successfully deployiny to heroku ,
thanks for your demonstration ! , this is my code on github https://github.com/jimmybow/Deploying-Plotly-Dash-To-Heroku