Unable to deploy Dash application on Linux using Gunicorn

Hi,

I am developing an application using dash and want to host it using Gunicorn on linux platform.
The following is how I have deployed it.

my dash application, file name: analyzer.py

import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import flask

<data_frame definitions>


#server = flask.Flask(__name__)  ---> Tried this approach also
app = dash.Dash(server=server)
server = app.server    


<app.layout>

<Call backs>

## at the end

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

Created an index.py for Gunicorn

from MyPoC.analyzer import server as application

application

When I use the below command, I see no errors on the screen, but yet I can’t reach the application from the browser.

[user1@myHost]$ gunicorn index:application -b <public IP>:8000

[2021-04-16 16:57:58 +0200] [8334] [INFO] Starting gunicorn 20.0.4
[2021-04-16 16:57:58 +0200] [8334] [INFO] Listening at: http://<public IP>:8000 (8334)
[2021-04-16 16:57:58 +0200] [8334] [INFO] Using worker: sync
[2021-04-16 16:57:58 +0200] [8345] [INFO] Booting worker with pid: 8345

I see that the port is listening, however, I am not able to open my dashboard on the server’s public IP and 0.0.0.0
The port 8000 is in listen mode

[user1@~]$ netstat -an | grep -i 8000
tcp        0      0 <public IP>:8000      0.0.0.0:*               LISTEN
[user1@~]$

I have also tried calling server from dash application directly through gunicorn.

$ gunicorn analyzer:server -b <public IP>:8000 but still my dashboard doesn’t open.

Could you please tell me where I am going wrong. Kindly forgive me if I have made any fundamental mistake. I would really appreciate if you could guide me and show a path towards resolution.

Thanks and Regards
Karthik

To be honest, I don’t see any obvious mistake. Could you try this?

MyPoC/analyzer.py:

import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd

<data_frame definitions>


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


<app.layout>

<Call backs>

## at the end

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

index.py:

from MyPoC.analyzer import app
application = app.server

if __name__ == '__main__':
    application.run()

To run it:
$ gunicorn index:application --bind=0.0.0.0:8000

Hi

Thank you for your response.

I have tried your suggestion. But still, I am not able to view my dashboard on the browser unfortunately.

:frowning:

There could be a firewall or similar in the way. Are you seeing any response in your browser at all?

You could try using the internal local ip 127.0.0.1 to see if that works.

Hi Mark,

I have tried on localhost (127.0.0.1), but to no success.

I tried wget on the public IP and the port and I got a “connected” and 200 OK response.
Below is the output.

[user1@~]$ wget 10.61.216.128:8000
--2021-04-20 19:45:44--  http://10.61.216.128:8000/
Connecting to 10.61.216.128:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1675 (1.6K) [text/html]
Saving to: ‘index.html.1’

100%[====================>] 1,675       --.-K/s   in 0s

2021-04-20 19:45:44 (142 MB/s) - ‘index.html.1’ saved [1675/1675]

Below is the content of the html file.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta charset="UTF-8">
        <title>Dash</title>
        <link rel="icon" type="image/x-icon" href="/_favicon.ico?v=1.17.0">

    </head>
    <body>

<div id="react-entry-point">
    <div class="_dash-loading">
        Loading...
    </div>
</div>

        <footer>
            <script id="_dash-config" type="application/json">{"url_base_pathname": null, "requests_pathname_prefix": "/", "ui": false, "props_check": false, "show_undo_redo": false, "suppress_callback_exceptions": false, "update_title": "Updating..."}</script>
            <script src="/_dash-component-suites/dash_renderer/polyfill@7.v1_8_3m1604000066.8.7.min.js"></script>
<script src="/_dash-component-suites/dash_renderer/react@16.v1_8_3m1604000066.14.0.min.js"></script>
<script src="/_dash-component-suites/dash_renderer/react-dom@16.v1_8_3m1604000066.14.0.min.js"></script>
<script src="/_dash-component-suites/dash_renderer/prop-types@15.v1_8_3m1604000066.7.2.min.js"></script>
<script src="/_dash-component-suites/dash_html_components/dash_html_components.v1_1_1m1599150811.min.js"></script>
<script src="/_dash-component-suites/dash_core_components/dash_core_components.v1_13_0m1604001906.min.js"></script>
<script src="/_dash-component-suites/dash_core_components/dash_core_components-shared.v1_13_0m1604001906.js"></script>
<script src="/_dash-component-suites/dash_renderer/dash_renderer.v1_8_3m1604000091.min.js"></script>
            <script id="_dash-renderer" type="application/javascript">var renderer = new DashRenderer();</script>
        </footer>
    </body>

So am I right in thinking that the browser is not able to reach the application? Linux tools like wget is able to reach the public IP and port? What does this mean.

It means that your Dash app is being served correctly, and the issue is with your browser. You’ll need to be more specific with exactly what you are/are not seeing in your browser. Checking that it works with other sources (ie other machines, or simple servers such as python -m http.server 8000 on the machine in question) would be one next step, as would checking any browser proxy settings.

Hi Mark and sislvacl

Even though the port was listening, I had to add it to firewalld a firewall management solution for Linux. It’s embarrassing really, such a basic miss. I am truly sorry and apologize for wasting your time.

It is opening now on browser and now I can continue to make more improvements and add authentication and stuff.

Thanks and Regards
Karthik