Deploying Dash app on a wsgi service

Hey guys,

I am trying to deploy dash as a wsgi service, following similar steps as in the DigitalOcean tutorial:

https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps

This is my code (truncated the callback and layout sections):

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import plotly.express as px
import dash_auth
import dash_enterprise_auth as auth

VALID_USERNAME_PASSWORD_PAIRS = [['hello', 'world']]

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__,external_stylesheets=external_stylesheets)

app.layout = html.Div([])

auth = dash_auth.BasicAuth(
    app,
    VALID_USERNAME_PASSWORD_PAIRS
)

@app.callback(
)
def update_figure(n_clicks,state1,state2,state3):

    return fig, u'''The Button has been pressed {} times, Input 1 is "{}", and Input 2 is "{}"'''.format(n_clicks, state1, state2)

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

and my flaskapp.wsgi file contains this:

#!/usr/bin/python4.8
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")

from FlaskApp import app as application
#from FlaskApp import server as application
#application.secret_key = 'xx'

The error log says this:

TypeError: 'Dash' object is not callable

I suspect the exact same mechanics don’t work for Dash as for Flask (I’ve literally applied the same construction of the wsgi file from the flask tutorial to this), but can’t really figure out how to modify it to get it to work

Answering my own question:

Modified wsgi file to include the below - and everything now works

from myapp import app
application = app.server

Taken from:
https://help.pythonanywhere.com/pages/DashWSGIConfig/

1 Like