Prepare Dash for Deployment
Pre-requisites
- Store application dependencies in a
requirements.txt
file. This file should be located alongside yourapp.py
file.
Define create_app
Function
Define a create_app
function in app.py that returns a Dash app instance.
from dash import Dash
def create_app():
app = Dash(__name__)
app.layout = html.Div("Hello, World!") # Do your magic here...
return app
If you want the ability to run your Dash application locally, you can add the following code to the bottom of your app.py file.
# Make sure to set the DEBUG and PORT environment variables.
if __name__ == "__main__" and os.getenv('DEBUG') == 'True':
create_app().run_server(debug=True, port=os.getenv('PORT', 8050))
Setup Data Deployments
If you are deploying a static site built on changing data, you can store the data in a directory, e.g. src/data/
,
within your application and it will be deployed with your application. Your code pipeline will also include a data
trigger that will redeploy your application with the new data when the data changes. See the
Static Deployments page for more information.