Forums

Deploy an interactive web app using dash (plot.ly)

Greeting fellow slytherins

In a search to build an interactive data analytics app on flask, I stumbled upon this framework for building interactive web applications. It is build on top of flask, so I was wondering how could I deploy a dash app on py_anywhere? Could I deploy it inside an other flask app (someway)?

Any help would be appreciated. Thanks

From a quick cursory glance, I don't see anything that makes me worry it wouldn't work, so I'd say it's definitely worth a try...

Glad to hear that. However I don't know how to approach it. Dash behaving like a server, should I deploy it directly or build a new flask app and deploy it within that. I am new to flask and web development so any help would be great.

That's probably a good question to ask of the Dash maintainers -- the specific question to ask them (or to search for in their documentation) would be how you deploy it as a WSGI app. WSGI is the protocol our system uses to communicate between the web servers and your code.

Alright, thanks for your answer @giles. Since then I went with another, simpler route. But I will keep that in mind in case I want to give dash another chance. Cheers

I'm also interested in this, any developments?

Try going through the dash tutorial? At a cursory glance it is compatible with PythonAnywhere (so no new developments there).

If you are confused about how to setup dash on PythonAnywhere, I would suggest starting a flask app under the webapps tab. You will see a sample flask app which exports an app object (this is imported by the wsgi.py file, and is what we use to run your server). You can then add to / change that flask app by adding in dash components. (eg: by changing the line app = Flask(__name__) to app = dash.Dash().

Giles, this is another one for the list of webapps that people might be offered as default installs!!

Good suggestion! I've added it to our to-do list. No promises as to timelines, though...

Hi Giles, I did the following in order to try dash:

  • Create a virtualenv and install required packages for dash

  • Modified flask_app.py with the following code

  • I didnt modify the WSGI file

I got this error on the logs:

2017-07-21 17:08:59,601: Error running WSGI application

2017-07-21 17:08:59,601: TypeError: 'Dash' object is not callable

How can I solve it?

Thank you

it looks like you're following the official instructions correctly, so that's a strange error. maybe ask the Dash developers, or maybe they have a support forum?

Hi there, someone else had a similar problem. see if this solution works for you? https://www.pythonanywhere.com/forums/topic/11625/#id_post_43420

Hi harry, thank you very much for the info. Now is working! :)

Hi. I have a similar issue with Dash not deploying.

The webapp worked locally, once deployed the regular parts of the site are working fine. The Dash module however produces an error in passing the app to flask.

The webapp has three plotly dash apps that have been configured with Django-plotly-Dash, they work locally.

The error log provides the following:

File "/home/TheBoatShed/.virtualenvs/myenv/lib/python3.9/site-packages/dash/dash.py", line 494, in __init__ self.init_app()
File "/home/TheBoatShed/.virtualenvs/myenv/lib/python3.9/site-packages/dash/dash.py", line 558, in init_app
self.server.before_request(self._setup_server)
File "/home/TheBoatShed/.virtualenvs/myenv/lib/python3.9/site-packages/flask/scaffold.py", line 39, in wrapper_func 
if self._is_setup_finished():
File "/home/TheBoatShed/.virtualenvs/myenv/lib/python3.9/site-packages/flask/app.py", line 517, in   _is_setup_finished
return self.debug and self._got_first_request
File "/home/TheBoatShed/.virtualenvs/myenv/lib/python3.9/site-packages/flask/app.py", line 792, in debug
return self.config["DEBUG"]
KeyError: 'DEBUG

DEBUG is set to False in Settings.py. and the WSGI file has the following

DJANGO 
# To use your own django app use code like this:
import os
import sys

path = '/home/TheBoatShed/demo'
if path not in sys.path:
sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'demosite.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

My assumption is that flask is not reading the debug setting in the settings file. I have tried to add locally in the files however as per the Flask docs this has not worked.

Does anyone have any suggestions I could try.

Thanks Brendon

You'll need to check the documentation of django-plotly-dash to make sure that Django settings (where you have the DEBUG key set) are transferred into Flask settings (which is what is being looked up by the code that is raising the error)