【问题标题】:How to integrate the Plotly dash with the flask app. How to connect them?如何将 Plotly dash 与烧瓶应用程序集成。如何连接它们?
【发布时间】:2022-01-06 12:25:30
【问题描述】:
    **Python code I used** 

正如您在此 python 代码中所见,我正在尝试在烧瓶应用程序中重定向绘图模板。 # Step – 1(导入必要的库) 从烧瓶导入(Flask、render_template、请求、重定向、会话) 将熊猫导入为 pd 将 plotly.express 导入为 px 将 matplotlib.pyplot 导入为 plt 从 flask.helpers 导入 url_for

    # Step – 2 (configuring your application)
    app = Flask(__name__)
    app.secret_key = 'xyz'
    
    # step – 3 (creating a dictionary to store information about users)
    user = {"username": "abc", "password": "123"}
    
    # Step – 4 (creating route for login)
    @app.route('/', methods=['POST', 'GET'])
    def login():
        if (request.method == 'POST'):
            username = request.form.get('username')
            password = request.form.get('password')
            if username == user['username'] and password == user['password']:
                session['user'] = username
                return redirect('/New_temp')
    
            return "<h1>Wrong username or password</h1>"
    
        return render_template("login.html")
    
    # Step -5(creating route for dashboard and logout)
    @app.route('/New_temp')
    def home():
     if ('user' in session and session['user'] == user['username']):
         return render_template('New_temp.html')
    
    @app.route('/graph', methods=['POST'])
    def graph():
        return render_template('Machine_graph.html')
        pass
        #subprocess.call('Machine_graph.html')
        #return home()
    
        return '<h1>You are not logged in.</h1>'
    
    # Step -7(run the app)
    if __name__== '__main__':
        app.run(debug=True)

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python flask plotly


【解决方案1】:

使用 'server' 参数将您的 Flask 应用程序传递到 Dash 对象中。

dash_app = Dash(__name__, server=app, url_base_pathname='/dash/')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-28
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 2021-09-05
    相关资源
    最近更新 更多