Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Dash server with waitress

I have a dashboard application written in Dash framework. It also has a few Restful API's written using flask. I am adding flask app to Dash server, as

import dash
import flask
import dash_bootstrap_components as dbc

flask_server = flask.Flask(__name__)
app = dash.Dash(__name__,server=flask_server, external_stylesheets=[dbc.themes.BOOTSTRAP])

And am running the server as

from dashboard import app
from waitress import serve

if __name__ == "__main__":
    app.title = 'Litmus'
    app.run_server(debug=False)
    # serve(app,host="0.0.0.0",port=8050)

The above code works fine when I am using app.run_server(debug=False) but it throws excetion when I use waitress to run the server. When I use following lines

#app.run_server(debug=False)
serve(app,host="0.0.0.0",port=8050)

I get following error

ERROR:waitress:Exception while serving /
Traceback (most recent call last):
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\channel.py", line 397, in service
    task.service()
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 168, in service
    self.execute()
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 434, in execute
    app_iter = self.channel.server.application(environ, start_response)
TypeError: 'Dash' object is not callable
ERROR:waitress:Exception while serving /favicon.ico
Traceback (most recent call last):
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\channel.py", line 397, in service
    task.service()
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 168, in service
    self.execute()
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 434, in execute
    app_iter = self.channel.server.application(environ, start_response)
TypeError: 'Dash' object is not callable
like image 926
philein-sophos Avatar asked Sep 01 '26 14:09

philein-sophos


1 Answers

It's not working because you're passing the Dash app instead of the Flask app to serve.

So instead of this:

serve(app,host="0.0.0.0",port=8050)

pass the Flask app instance like this:

serve(app.server, host="0.0.0.0", port=8050)
like image 138
Bas van der Linden Avatar answered Sep 04 '26 02:09

Bas van der Linden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!