gunicorn fails to parse app.server for Dash, causing deployment to fail

0

I’m trying to deploy a Dash app with Render, and keep getting this error:

objgunicorn.errors.AppImportError: Failed to parse 'app.server' as an attribute name or function call.

Below is the relevant code:

app = Dash(__name__)
server=app.server

app.layout = html.Div(
    [
        html.Div(
            className= 'title',
            children= 'The Show - Season Stats'
        ),
        html.Div(
            dash_table.DataTable(
                statsdf.to_dict('records'),
                id = 'table',
                columns=[{'id': c, 'name': c, 'type': 'text'} for c in statsdf.columns],
                sort_action='native',
                style_data_conditional= [
                    {
                        'if': {
                            'column_id': 'Team'
                        },
                        'textAlign': 'left',
                        'width': '10%',
                        'paddingLeft': '1%'

                    }
                ],
                style_data= {'fontFamily': 'Nunito Sans',
                             'width': '5%',
                             'textAlign': 'center',
                             'height': '40px'},
                style_header_conditional= [
                    {
                        'if': {
                            'column_id': 'Team'
                        },
                        'textAlign': 'left',
                        'paddingLeft': '1%'
                    }
                ],
                style_header= {'fontFamily': 'Nunito Sans',
                               'fontWeight': 'bold',
                               'textAlign': 'center',
                               'height': '10%'}
            )
        )
    ]
)

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

And here is the content of my Procfile. I think there may be an issue the way that this is being read during deployment, but I’m not certain.

web: gunicorn Fantasy_Stats_Tracking:server

Any help would be great, thanks in advance!

Still having this issue. Have tried a variety of things including using:

web: gunicorn Fantasy_Stats_Tracking:app
web: gunicorn Fantasy_Stats_Tracking:app.server

I also tried creating a new project and cleaning up the file structure a bit. I can still get it to run locally, but the problem still occurs when I try to deploy.

I’m not sure what Render is, or what the name of your module that file contains is contained within, but let’s say your Dash code above was in a file called main.py. If so, then you would invoke Gunicorn like so:

gunicorn main:server

Since the attribute after the : should be the Flask instance.

Hello, thanks for the response. Render is similar to Heroku for deploying applications. I tried on Heroku first but ran into too many issues.

I did solve this problem, though it was unrelated to my code. I’ll put what I did wrong here in case anyone ever makes this mistake again and it looking for a solution.

  1. Started trying to deploy using Heroku
  2. Created Procfile with web: gunicorn app:app
  3. Ran into issues, looked for alternatives to Heroku, found Render.
  4. Deployed through Render using GitHub repo integration.
  5. Got errors with the Procfile not being referenced.
  6. Find that web: gunicorn app:app is something that is set in the Render dashboard, and a Procfile wasn’t needed.
  7. Changed the “Start Command” in “Settings” on Render Dashboard to
    web: gunicorn app:server
  8. Success
1 Like