I am trying to integrate my Dashboard built with dash into a flask app that does other things. I wanted it to display the dashboard on http://127.0.0.1:5000/Dashboard . I have gone through a lot of resources and still not clear. The URL keeps giving me a 404 Not found error but the URL to all other flask routes work.
app.py
from flask import Flask, render_template, request, redirect
import flask
from dashboard import *
app = Flask(__name__)
@app.route('/Recalculate', methods = ['GET','POST'])
def calculate():
return render_template('recalculate.html', tables=[final_merged_data.to_html(classes='data', index=False)], titles=round_data.columns.values)
@app.route('/Dashboard')
def render_dashboard():
return redirect("/pathname/")
if __name__ == '__main__':
app.run(debug=True)
dashboard.py
import dash
import flask
from flask import Flask
import dash_table
import numpy
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
server = flask.Flask(__name__)
app_dash = dash.Dash(__name__,server=server, routes_pathname_prefix="/pathname/", external_stylesheets=external_stylesheets)
colors = {
'background': '#111111',
'text': '#7FDBFF'
}
# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
data = [trace1, trace2]
layout = go.Layout(barmode = 'group',xaxis_title="Day of the month", yaxis_title="Power Generated in MW")
fig = go.Figure(data = data, layout = layout)
fig.update_layout(
plot_bgcolor=colors['background'],
paper_bgcolor=colors['background'],
font_color=colors['text']
)
app_dash.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
html.H1(
children='Hello George',
style={
'textAlign': 'center',
'color': colors['text']
}
),
html.Div(children='Predicted output from your wind and solar plants', style={
'textAlign': 'center',
'color': colors['text']
})
if __name__ == '__main__':
app_dash.run_server(debug=True)
I am not an expert, but I understand that for doing that you have to declare the dash app as a function in your code, let's say:
def init_dash(server):
dash_app = dash.Dash(
server=server, ...
You can have a look to this web for more professional details.
Cheers
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.