Ananth Nag
Ananth Nag

Reputation: 21

Dash application is not running on gunicorn nginx wsgi sever

I've developed one dash application for my data in Flask framework. The code is running on Local Server. But when I run this on production by using Gunicorn wsgi by configuring Nginx server, I'm not getting any results.

The project directory looks like follows:

flask_application
   | static
     |-
   | templates
     |- home.html
   | app.py
   | wsgi.py

I'm using Centos7 ssh connected by Putty. Here is the code which I'm trying to execute on wsgi server and the command used for running the application.

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
from flask import Flask, render_template
import pandas as pd

server = Flask(__name__)
app = dash.Dash(__name__, server=server)

@app.route("/")
def home_conf():
    return render_template("home.html")


df= pd.read_csv('my_dataframe.csv')
df= df[1:]
features = df.columns
df_types= features[1:] #don't want the Customer column


app.layout = html.Div([
    html.Div([
    #Here is the interactive component
        html.Div([
            dcc.Dropdown(
                id='yaxis',
                options=[{'label':i,'value':i} for i in 
df_types],
            value='df-type'
        )
    ], style={'width': '60%'})
]),
html.Div([dcc.Graph(
    id='df-graphic',
    figure={
        'data': [go.Scatter(
            x=df['Lender'],
            y=[0,0],
            mode='markers'
        )],
        'layout': go.Layout(
            title = 'Use the dropdown to display the chart ...',
            xaxis={'tickformat': 'd'}
        )
    }
    )
], style={'width':'70%', 'display':'inline-block'}),
html.Div([dcc.Graph(
    id='df-stacked',
    figure={
        'data': [go.Bar(
            x=df['Lender'],
            y=df['Login'],
            name='Login'
            ),
            go.Bar(
                            x=df['Lender'],
                            y=df['Approved'],
                            name='Approved'
                            ),
            go.Bar(
                            x=df['Lender'],
                            y=df['Reject'],
                            name='Reject'
                            ),
            go.Bar(
                            x=df['Lender'],
                            y=df['Agreement'],
                            name='Agreement'
                            ),
            go.Bar(
                            x=df['Lender'],
                            y=df['Disbursed'],
                            name='Disbursed'
                            ),
            go.Bar(
                            x=df['Lender'],
                            y=df['Cancelled'],
                            name='Cancelled'
                            ),
        ],
        'layout': go.Layout(
            title ='Customer Count in the finance from August, 2019',
            barmode='stack'
        )
    }
    )
], style={'width':'70%', 'display':'inline-block'}),
html.Div([dcc.Graph(
    id='df-boxplot',
    figure={
        'data': [go.Box(
        y=df['Login'],
        name='Login'
        ),
        go.Box(
                    y=df['Approved'],
                    name='Approved'
                    ),
        go.Box(
                    y=df['Reject'],
                    name='Reject'
                    ),
        go.Box(
                    y=df['Agreement'],
                    name='Agreement'
                    ),
        go.Box(
                    y=df['Disbursed'],
                    name='Disbursed'
                    ),
        go.Box(
                    y=df['Cancelled'],
                    name='Cancelled'
                    ),
        ],
        'layout': go.Layout(
        title='Customer Count in the Finance, August 2019'
        )
    }
)
], style={'width':'70%', 'display':'inline-block'}),
html.Div([
    dcc.Markdown(children=markdown_text)
])
], style={'padding':10})

#Here is the callback
@app.callback(
    Output('df-graphic', 'figure'),
    [Input ('yaxis', 'value')])
def update_graphic(yaxis_lbit):
    return {
        'data': [go.Scatter(
            x=df['Lender'],
            y=df[yaxis_lbit],
            mode='lines+markers',
            marker={
                'size': 15,
                'opacity': 0.5,
                'line': {'width':0.5, 'color':'white'}
            }
        )],
        'layout': go.Layout(
            title='{} in the Finance by Customer Count, 
 August 2019'.format(yaxis_lbit),
        xaxis={'title': 'Lender'},
        yaxis={'title': yaxis_lbit},
        hovermode='closest'
    )
}


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

The following is the command which I'm using for running the application in WSGi after connecting to centos ssh.

gunicorn app:app

Can anyone explain why I'm not getting the results after executing in wsgi server and what changes will be needed in the code. Any help would be greatly appreciated. Thank you.

Upvotes: 2

Views: 2226

Answers (1)

Gabe
Gabe

Reputation: 111

You are running dash app inside flask server. Try gunicorn app:server Similarly, you should change your "if mean" statement

Upvotes: 1

Related Questions