# Run a dash app inside a flask app

**URL:** <https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331>\
**Category:** Dash Python\
**Created:** [May 16, 2018, 8:57am UTC](https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331 "2018-05-16T08:57:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ntdx787](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/ntdx787/32/3216_2.png) [@ntdx787](https://community.plotly.com/u/ntdx787)\
**Post date:** [May 16, 2018, 8:57am UTC](https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331/1 "2018-05-16T08:57:54Z")

</div>

Hello,  
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

flaskapp.py

> ```
> server = Flask( __name__ ) 
> @server.route('/dash')
> def dash_chart():
> dashapp.start()
> 
> if __name__ == " __main__":
> server.run(debug=True)
> 
> ```

dashapp.py

> ```
> def start():
> app = dash.Dash( __name__ )
> app.layout = html.Div('Hello World')
> if __name__ ==' __main__':
> app.run_server(debug=True)
> 
> ```

---

<div class="post-metadata">

**Author:** ![Blaceus](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/blaceus/32/2992_2.png) [@Blaceus](https://community.plotly.com/u/Blaceus)\
**Post date:** [May 30, 2018, 2:24pm UTC](https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331/2 "2018-05-30T14:24:30Z")

</div>

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(
	children=[
            **stuff goes here**
	]
)

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

```

That’s how I’ve implemented my stuff and it works like a charm. 👨‍💻

---

<div class="post-metadata">

**Author:** ![sanks20](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@sanks20](https://community.plotly.com/u/sanks20)\
**Post date:** [April 9, 2019, 4:00pm UTC](https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331/4 "2019-04-09T16:00:34Z")

</div>

> [@Blaceus](#):
>
> server = flask.Flask( **name** ) app = dash.Dash( **name** , server=server)

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

---

<div class="post-metadata">

**Author:** ![Blaceus](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/blaceus/32/2992_2.png) [@Blaceus](https://community.plotly.com/u/Blaceus)\
**Post date:** [April 12, 2019, 1:15pm UTC](https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331/5 "2019-04-12T13:15:54Z")

</div>

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:

```auto
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. 🙂

---

<div class="post-metadata">

**Author:** ![nedned](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nedned/32/8795_2.png) [@nedned](https://community.plotly.com/u/nedned)\
**Post date:** [April 16, 2019, 5:27am UTC](https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331/6 "2019-04-16T05:27:58Z")

</div>

> [@Blaceus](#):
>
> ```python
> if __name__ == ' __main__': 
> app.run_server(debug=True, port=8050, host='127.0.0.1') 
> app.run_server(debug=True)
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![Blaceus](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/blaceus/32/2992_2.png) [@Blaceus](https://community.plotly.com/u/Blaceus)\
**Post date:** [April 16, 2019, 5:58am UTC](https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331/7 "2019-04-16T05:58:46Z")

</div>

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

```auto
if __name__ == ' __main__': 
    app.run_server(debug=True)

```

My IIS is defining IP and port for me.

---

<div class="post-metadata">

**Author:** ![nedned](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nedned/32/8795_2.png) [@nedned](https://community.plotly.com/u/nedned)\
**Post date:** [April 16, 2019, 6:01am UTC](https://community.plotly.com/t/run-a-dash-app-inside-a-flask-app/10331/8 "2019-04-16T06:01:08Z")

</div>

ah gotcha 🙂
