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!