Actually i am trying to integrate dash app with flask app. Dash app itself is running successfully. But when i add home page using flask app it stopped working. Do not know what is correct why to combine both apps together.
Actual idea is :
First page will be rendered using flask app having input box asking user to enter their auth token and click on submit button it will open second page dash plotly(Dashboard page)
Please assist me in solving this error. I am very keen to run dash app using flask app.
Files as below:
app.py
import dash
from flask import Flask
server = Flask(name)
#server.config.from_object(name)
#server.config[âSECRET_KEYâ] = âdevâ
wsgi_app = server.wsgi_app
app = dash.Dash(name, server=server)
#app = dash.Dash()
#server = app.server
app.config.suppress_callback_exceptions = True
Flask_form.py
from flask import render_template, flash, redirect, url_for, request
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField
from app import server, app
import figures
#App config.
DEBUG = True
#app = Flask(name)
server.config.from_object(name)
server.config[âSECRET_KEYâ] = âdevâ
class ReusableForm(Form):
name = TextField(âName:â, validators=[validators.required()])
@server.route(â/dash/â)
def load_dash(name):
return figures.dash_page(name)
#return âwelcome %sâ % name
@server.route("/", methods=[âGETâ, âPOSTâ])
def hello():
form = ReusableForm(request.form)
print(form.errors)
if request.method == 'POST':
token=request.form['name']
if form.validate():
return redirect(url_for('load_dash', name = token))
# Save the comment here.
#flash('Hello ' + name)
else:
flash('All the form fields are required. ')
return render_template('index.html', form=form)
if name == âmainâ:
server.run(debug=True)
Figures.py
from app import app
import dash_core_components as dcc
import dash_html_components as html
#app = dash.Dash()
def dash_page(value):
#app = dash.Dash() #pylint: disable=invalid-name
app.layout = serve_layout(value)
return app.layout
def serve_layout(value):
return html.Div(children=[
html.H1(children=âHello Dashâ),
html.Div(children='''
Dash: A web application framework for Python.
'''),
dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
],
'layout': {
'title': 'Dash Data Visualization'
}
}
)
])
if name == âmainâ:
print(âhelloâ)
#app.run_server(debug=True)
index.html
Reusable Form Demo {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %}-
{% for message in messages %}
- {{ message[1] }} {% endfor %}
<div class="input text">
{{ form.name.label }} {{ form.name }}
</div>
<div class="input submit">
<input type="submit" value="Submit" />
</div>
</form>
</body>