我正在尝试将dash内置的仪表板集成到一个flask应用程序中,该应用程序可以做其他事情。我想让它在http://127.0.0.1:5000/Dashboard上显示仪表板。我已经查阅了很多资料,但仍然不清楚。URL一直给我一个404NotFound错误,但所有其他flask路由的URL都有效
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)
我不是专家,但我明白要做到这一点,您必须在代码中将dash应用程序声明为函数,比如:
您可以查看此web以了解更专业的详细信息
干杯
相关问题 更多 >
编程相关推荐