Dash - pythonanywhere deployment issue

I am giving a try to Dash, but I am having issues deploying it to pythonanywhere.com.

I continue to get the Dash callback error every time. I saw a solution for heroku but it has not worked for me.

I am not an experienced programmer, but I have been playing with plotly lately; I think it is a great tool. I really want this to work as I would like my organization to buy some licenses in the future.

I would appreciate any help you can give me.

Below is the code and the error:

--------------------------------------------------------
Error:
2017-07-24 18:08:07,221: Error running WSGI application
2017-07-24 18:08:07,222: TypeError: 'Dash' object is not callable
--------

dashapp.py

# -*- coding: utf-8 -*-

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

server = Flask(__name__)
server.secret_key ='test'
#server.secret_key = os.environ.get('secret_key', 'secret')
app = dash.Dash(name = __name__, server = server)
app.config.supress_callback_exceptions = True

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    ),
    dcc.Input(id='my-id', value='initial value', type="text"),
    html.Div(id='my-div')
])

@app.callback(
    Output(component_id='my-div', component_property='children'),
    [Input(component_id='my-id', component_property='value')]
)
def update_output_div(input_value):
    return 'You\'ve entered "{}"'.format(input_value)

wsgi

import sys

path = '/home/******/******'
if path not in sys.path:
    sys.path.append(path)

from dashapp import app as application
2 Likes

@Mario.Romero - Thanks for reporting and thanks for the support! Hopefully we can get this working for you :+1:

Could you try changing the wsgi file from:

from dashapp import app as application

to

from dashapp import server as application

server” is the instance of the “flask” server and that’s what PythonAnywhere / wsgi will expect.

If that doesn’t end up working, I’ll create an account with PythonAnywhere and see if I can get it working :+1:

4 Likes

Thanks Chris,

This worked just fine. I will proceed to create a few more things with Dash and let you know if I have any questions.

Great Tool!

1 Like

Hi,
I had exactly the same error message with: from dashapp import app as application

On following your suggestion: from dashapp import server as application
I receive a new error message:

Error running WSGI application
ImportError: cannot import name ‘server’
File “/var/www/rupertjames_pythonanywhere_com_wsgi.py”, line 83, in
from charts import server as application

Could you suggest the cause and a solution?
Thanks.

The import line from dashapp import server as application assumes that you have an attribute server in the module dashapp. So you will need to ensure you have done one of the following:

server = Flask(__name__)
app = Dash(server=server)

or

app = Dash()
server = app.server
3 Likes

I’m trying a a multi-page project. I’ve used this example from
https://dash.plot.ly/urls

Structuring a Multi-Page App
Here’s how to structure a multi-page app, where each app is contained in a separate file.
File structure:

  • app.py
  • index.py
  • apps
    |-- init.py
    |-- app1.py
    |-- app2.py

It works just running “python index.py”, but that’s not OK for production.
My attempts creating a wsgi.py file and running
uwsgi --socket 0.0.0.0:8000 --protocol=http -w wsgi

have all failed.

Example:
wsgi.py:
from index import app as application
if name == “main”:
application.run()

Fails with error:
TypeError: ‘Dash’ object is not callable

Anyone have a working example? I’m using CentOS 7 to run this.

Further reflection on

Yields this as the secret sauce from the analytic_app project:

more wsgi.py
#   10/08/2019
from index import app
application=app.server

if __name__ == "__main__":
    application.run()

where i type: from dashapp import server as application i get a : no module named ‘dashapp’ what do i need to install?

Thanks a lot i had same issue just fixed with this method!

Thanks to @chriddp and @nedned years later this post contained the clues I needed to get my first PythonAnywhere deployed Dash app working. Cheers to this super supportive group!