Run a dash app inside a flask app

I currently have a flask app and I want to implement a dash app into it. However I’ve been running into multiple errors and I don’t really understand the document for dash deployment. Here is my code

server = Flask(__name__) 
def dash_chart():

if __name__ == "__main__":

def start():
    app = dash.Dash(__name__)
    app.layout = html.Div('Hello World')
    if __name__=='__main__':
1 Like

Is there a specific reason to have two separate scripts for this?
Will something like this solve your problem:

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

app.layout = html.Div(
            **stuff goes here**

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

That’s how I’ve implemented my stuff and it works like a charm. :man_technologist:

do you use @server.route(’/’) instead of @app.route(’/’) for all routes then?

I do not use routes so I do not understand your question…

If I need to grab data or scripts/functions from other folders I handle everything in Python. What I mean is say I need to grab some data from a file to plot I will do something like:

import pandas

with open('path/name_of_file.txt', 'r' as input_file):
   data = pandas.dataframe(input_file) #not correct syntax, but I hope you get the gesture of it

import plotly
'Do fancy stuff with my data using plotly and make an awesome plot'

import dash
'launch app and put in awesome plot'

Sorry I do not understand, but I hope this somehow helps. :slight_smile:

This probably isn’t working for the reason you think it is. The first call to run_server will block as you’ve now got a web server listening for incoming requests. So the second run_server won’t be executed.

Oh, I see I have made a typo (sorry)
The first line was some leftover code (which is usually outcommented) from before I started hosting my app through waitress.
It should just be

if __name__ == '__main__': 

My IIS is defining IP and port for me.

ah gotcha :slight_smile: