Running a Dash app within a Flask app









up vote
22
down vote

favorite
12












I have an existing Flask app, and I want to have a route to another app. More concretely, the second app is a Plotly Dash app. How can I run my Dash app within my existing Flask app?



@app.route('/plotly_dashboard') 
def render_dashboard():
# go to dash app


I also tried adding a route to the Dash instance, since it's a Flask app, but I get the error:



AttributeError: 'Dash' object has no attribute 'route'









share|improve this question



























    up vote
    22
    down vote

    favorite
    12












    I have an existing Flask app, and I want to have a route to another app. More concretely, the second app is a Plotly Dash app. How can I run my Dash app within my existing Flask app?



    @app.route('/plotly_dashboard') 
    def render_dashboard():
    # go to dash app


    I also tried adding a route to the Dash instance, since it's a Flask app, but I get the error:



    AttributeError: 'Dash' object has no attribute 'route'









    share|improve this question

























      up vote
      22
      down vote

      favorite
      12









      up vote
      22
      down vote

      favorite
      12






      12





      I have an existing Flask app, and I want to have a route to another app. More concretely, the second app is a Plotly Dash app. How can I run my Dash app within my existing Flask app?



      @app.route('/plotly_dashboard') 
      def render_dashboard():
      # go to dash app


      I also tried adding a route to the Dash instance, since it's a Flask app, but I get the error:



      AttributeError: 'Dash' object has no attribute 'route'









      share|improve this question















      I have an existing Flask app, and I want to have a route to another app. More concretely, the second app is a Plotly Dash app. How can I run my Dash app within my existing Flask app?



      @app.route('/plotly_dashboard') 
      def render_dashboard():
      # go to dash app


      I also tried adding a route to the Dash instance, since it's a Flask app, but I get the error:



      AttributeError: 'Dash' object has no attribute 'route'






      python flask plotly-dash






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 23 '17 at 21:00









      davidism

      61.6k12156175




      61.6k12156175










      asked Aug 23 '17 at 17:23









      zthomas.nc

      73831531




      73831531






















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          28
          down vote













          From the docs:




          The underlying Flask app is available at app.server.



          import dash
          app = dash.Dash(__name__)
          server = app.server


          You can also pass your own Flask app instance into Dash:



          import flask
          server = flask.Flask(__name__)
          app = dash.Dash(__name__, server=server)



          Now that you have the Flask instance, you can add whatever routes and other functionality you need.



          @server.route('/hello')
          def hello():
          return 'Hello, World!'



          To the more general question "how can I serve two Flask instances next to each other", assuming you don't end up using one instance as in the above Dash answer, you would use DispatcherMiddleware to mount both applications.



          dash_app = Dash(__name__)
          flask_app = Flask(__name__)

          application = DispatcherMiddleware(flask_app, '/dash': dash_app.server)





          share|improve this answer





























            up vote
            17
            down vote













            Set url_base_pathname in your Dash instance.



            app_flask = flask.Flask(__name__)

            app_dash = dash.Dash(__name__, server=app_flask, url_base_pathname='/pathname')


            Now you can redirect to your Plotly Dashboard app under any Flask routes you want.



            @app_flask.route('/plotly_dashboard') 
            def render_dashboard():
            return flask.redirect('/pathname')





            share|improve this answer





























              up vote
              3
              down vote













              Ok for those who are lazy enough like me, here is the code



              from dash import Dash
              from werkzeug.wsgi import DispatcherMiddleware
              import flask
              from werkzeug.serving import run_simple
              import dash_html_components as html

              server = flask.Flask(__name__)
              dash_app1 = Dash(__name__, server = server, url_base_pathname='/dashboard' )
              dash_app2 = Dash(__name__, server = server, url_base_pathname='/reports')
              dash_app1.layout = html.Div([html.H1('Hi there, I am app1 for dashboards')])
              dash_app2.layout = html.Div([html.H1('Hi there, I am app2 for reports')])
              @server.route('/')
              @server.route('/hello')
              def hello():
              return 'hello world!'

              @server.route('/dashboard')
              def render_dashboard():
              return flask.redirect('/dash1')


              @server.route('/reports')
              def render_reports():
              return flask.redirect('/dash2')

              app = DispatcherMiddleware(server,
              '/dash1': dash_app1.server,
              '/dash2': dash_app2.server
              )

              run_simple('0.0.0.0', 8080, app, use_reloader=True, use_debugger=True)





              share|improve this answer
















              • 1




                I tried your code . it looked like what I was looking for as a test case. I get the following: /usr/local/lib/python3.7/site-packages/flask/app.py", line 1107, in register_blueprint blueprint, self.blueprints[blueprint.name], blueprint.name AssertionError: A name collision occurred between blueprints <flask.blueprints.Blueprint object at 0x1133d8fd0> and <flask.blueprints.Blueprint object at 0x1139184a8>. Both share the same name "assets". Blueprints that are created on the fly need unique names.
                – user2945234
                Aug 21 at 18:05











              • Ran into the same problem. I notice that the method worked for one redirection, but not for two redirections to dask apps. I have no clue how the change the assets name.
                – Kehlin Swain
                Sep 25 at 1:22










              • It seem that you have to take care of the flask version you use, I had two different experiences when using flask 1.0 and flask 0.12.
                – JustInTime
                Sep 28 at 7:40

















              up vote
              -2
              down vote













              To solve this issue, here is what I did and was successful. This should be documented in official DASH documentation



              ####################################
              import dash_core_components as dcc
              import dash_html_components as html
              from dash import Dash
              from dash.dependencies import Input, State, Output

              from flask import Flask, flash, redirect, render_template, request, session, abort, url_for, json, make_response

              url_router=''

              @application.route("/view_tables", methods=['GET','POST'])
              def view_tabales:
              # Logic for displaying dashboard using Dash
              server.layout = html.Div(
              children=[
              #division for graph 1
              html.Div([html.H1(children='Capital Charge'),],className='text-center'),

              html.Div([html.Div([html.H3(children='''Correlation for assets'''),],className='text-primary'),
              # define the graph
              dcc.Graph(
              id='Delta-graph',
              figure=
              'data': [
              'x': df_delta['Correlation_Level'],
              'y': df_delta['Capital_Charge'],
              'type': 'bar',
              'name': 'Delta',
              #'domain': 'x': [0, .48],'y': [0, .49],

              ],
              # sizes the graph
              'layout':
              'title': 'Delta','margin': 'l': 10, 'r': 0, 't': 30, 'b': 10,
              "height":300,


              )],className='col-md-4'),
              url_router = 'Dash(__name__,server=application, url_base_pathname="/dash")'


              Then you can control which dashboard it is headed from inside flask



              if url_router !='':
              server = url_router

              server.layout = html.Div(children = [html.H1(children = ' MEP dashboard - error 404')])


              # run the app.
              if __name__ == "__main__":
              # Setting debug to True enables debug output. This line should be
              # removed before deploying a production app.
              server.secret_key = os.urandom(12)
              server.run_server(debug=True,port=5000)


              you can create different functions with different graphs between the Flask code and keep calling the code in dash






              share|improve this answer




















                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45845872%2frunning-a-dash-app-within-a-flask-app%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                28
                down vote













                From the docs:




                The underlying Flask app is available at app.server.



                import dash
                app = dash.Dash(__name__)
                server = app.server


                You can also pass your own Flask app instance into Dash:



                import flask
                server = flask.Flask(__name__)
                app = dash.Dash(__name__, server=server)



                Now that you have the Flask instance, you can add whatever routes and other functionality you need.



                @server.route('/hello')
                def hello():
                return 'Hello, World!'



                To the more general question "how can I serve two Flask instances next to each other", assuming you don't end up using one instance as in the above Dash answer, you would use DispatcherMiddleware to mount both applications.



                dash_app = Dash(__name__)
                flask_app = Flask(__name__)

                application = DispatcherMiddleware(flask_app, '/dash': dash_app.server)





                share|improve this answer


























                  up vote
                  28
                  down vote













                  From the docs:




                  The underlying Flask app is available at app.server.



                  import dash
                  app = dash.Dash(__name__)
                  server = app.server


                  You can also pass your own Flask app instance into Dash:



                  import flask
                  server = flask.Flask(__name__)
                  app = dash.Dash(__name__, server=server)



                  Now that you have the Flask instance, you can add whatever routes and other functionality you need.



                  @server.route('/hello')
                  def hello():
                  return 'Hello, World!'



                  To the more general question "how can I serve two Flask instances next to each other", assuming you don't end up using one instance as in the above Dash answer, you would use DispatcherMiddleware to mount both applications.



                  dash_app = Dash(__name__)
                  flask_app = Flask(__name__)

                  application = DispatcherMiddleware(flask_app, '/dash': dash_app.server)





                  share|improve this answer
























                    up vote
                    28
                    down vote










                    up vote
                    28
                    down vote









                    From the docs:




                    The underlying Flask app is available at app.server.



                    import dash
                    app = dash.Dash(__name__)
                    server = app.server


                    You can also pass your own Flask app instance into Dash:



                    import flask
                    server = flask.Flask(__name__)
                    app = dash.Dash(__name__, server=server)



                    Now that you have the Flask instance, you can add whatever routes and other functionality you need.



                    @server.route('/hello')
                    def hello():
                    return 'Hello, World!'



                    To the more general question "how can I serve two Flask instances next to each other", assuming you don't end up using one instance as in the above Dash answer, you would use DispatcherMiddleware to mount both applications.



                    dash_app = Dash(__name__)
                    flask_app = Flask(__name__)

                    application = DispatcherMiddleware(flask_app, '/dash': dash_app.server)





                    share|improve this answer














                    From the docs:




                    The underlying Flask app is available at app.server.



                    import dash
                    app = dash.Dash(__name__)
                    server = app.server


                    You can also pass your own Flask app instance into Dash:



                    import flask
                    server = flask.Flask(__name__)
                    app = dash.Dash(__name__, server=server)



                    Now that you have the Flask instance, you can add whatever routes and other functionality you need.



                    @server.route('/hello')
                    def hello():
                    return 'Hello, World!'



                    To the more general question "how can I serve two Flask instances next to each other", assuming you don't end up using one instance as in the above Dash answer, you would use DispatcherMiddleware to mount both applications.



                    dash_app = Dash(__name__)
                    flask_app = Flask(__name__)

                    application = DispatcherMiddleware(flask_app, '/dash': dash_app.server)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 25 '17 at 14:10

























                    answered Aug 23 '17 at 20:50









                    davidism

                    61.6k12156175




                    61.6k12156175






















                        up vote
                        17
                        down vote













                        Set url_base_pathname in your Dash instance.



                        app_flask = flask.Flask(__name__)

                        app_dash = dash.Dash(__name__, server=app_flask, url_base_pathname='/pathname')


                        Now you can redirect to your Plotly Dashboard app under any Flask routes you want.



                        @app_flask.route('/plotly_dashboard') 
                        def render_dashboard():
                        return flask.redirect('/pathname')





                        share|improve this answer


























                          up vote
                          17
                          down vote













                          Set url_base_pathname in your Dash instance.



                          app_flask = flask.Flask(__name__)

                          app_dash = dash.Dash(__name__, server=app_flask, url_base_pathname='/pathname')


                          Now you can redirect to your Plotly Dashboard app under any Flask routes you want.



                          @app_flask.route('/plotly_dashboard') 
                          def render_dashboard():
                          return flask.redirect('/pathname')





                          share|improve this answer
























                            up vote
                            17
                            down vote










                            up vote
                            17
                            down vote









                            Set url_base_pathname in your Dash instance.



                            app_flask = flask.Flask(__name__)

                            app_dash = dash.Dash(__name__, server=app_flask, url_base_pathname='/pathname')


                            Now you can redirect to your Plotly Dashboard app under any Flask routes you want.



                            @app_flask.route('/plotly_dashboard') 
                            def render_dashboard():
                            return flask.redirect('/pathname')





                            share|improve this answer














                            Set url_base_pathname in your Dash instance.



                            app_flask = flask.Flask(__name__)

                            app_dash = dash.Dash(__name__, server=app_flask, url_base_pathname='/pathname')


                            Now you can redirect to your Plotly Dashboard app under any Flask routes you want.



                            @app_flask.route('/plotly_dashboard') 
                            def render_dashboard():
                            return flask.redirect('/pathname')






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Feb 9 at 13:12









                            davidism

                            61.6k12156175




                            61.6k12156175










                            answered Dec 8 '17 at 13:36









                            chanioxaris

                            32626




                            32626




















                                up vote
                                3
                                down vote













                                Ok for those who are lazy enough like me, here is the code



                                from dash import Dash
                                from werkzeug.wsgi import DispatcherMiddleware
                                import flask
                                from werkzeug.serving import run_simple
                                import dash_html_components as html

                                server = flask.Flask(__name__)
                                dash_app1 = Dash(__name__, server = server, url_base_pathname='/dashboard' )
                                dash_app2 = Dash(__name__, server = server, url_base_pathname='/reports')
                                dash_app1.layout = html.Div([html.H1('Hi there, I am app1 for dashboards')])
                                dash_app2.layout = html.Div([html.H1('Hi there, I am app2 for reports')])
                                @server.route('/')
                                @server.route('/hello')
                                def hello():
                                return 'hello world!'

                                @server.route('/dashboard')
                                def render_dashboard():
                                return flask.redirect('/dash1')


                                @server.route('/reports')
                                def render_reports():
                                return flask.redirect('/dash2')

                                app = DispatcherMiddleware(server,
                                '/dash1': dash_app1.server,
                                '/dash2': dash_app2.server
                                )

                                run_simple('0.0.0.0', 8080, app, use_reloader=True, use_debugger=True)





                                share|improve this answer
















                                • 1




                                  I tried your code . it looked like what I was looking for as a test case. I get the following: /usr/local/lib/python3.7/site-packages/flask/app.py", line 1107, in register_blueprint blueprint, self.blueprints[blueprint.name], blueprint.name AssertionError: A name collision occurred between blueprints <flask.blueprints.Blueprint object at 0x1133d8fd0> and <flask.blueprints.Blueprint object at 0x1139184a8>. Both share the same name "assets". Blueprints that are created on the fly need unique names.
                                  – user2945234
                                  Aug 21 at 18:05











                                • Ran into the same problem. I notice that the method worked for one redirection, but not for two redirections to dask apps. I have no clue how the change the assets name.
                                  – Kehlin Swain
                                  Sep 25 at 1:22










                                • It seem that you have to take care of the flask version you use, I had two different experiences when using flask 1.0 and flask 0.12.
                                  – JustInTime
                                  Sep 28 at 7:40














                                up vote
                                3
                                down vote













                                Ok for those who are lazy enough like me, here is the code



                                from dash import Dash
                                from werkzeug.wsgi import DispatcherMiddleware
                                import flask
                                from werkzeug.serving import run_simple
                                import dash_html_components as html

                                server = flask.Flask(__name__)
                                dash_app1 = Dash(__name__, server = server, url_base_pathname='/dashboard' )
                                dash_app2 = Dash(__name__, server = server, url_base_pathname='/reports')
                                dash_app1.layout = html.Div([html.H1('Hi there, I am app1 for dashboards')])
                                dash_app2.layout = html.Div([html.H1('Hi there, I am app2 for reports')])
                                @server.route('/')
                                @server.route('/hello')
                                def hello():
                                return 'hello world!'

                                @server.route('/dashboard')
                                def render_dashboard():
                                return flask.redirect('/dash1')


                                @server.route('/reports')
                                def render_reports():
                                return flask.redirect('/dash2')

                                app = DispatcherMiddleware(server,
                                '/dash1': dash_app1.server,
                                '/dash2': dash_app2.server
                                )

                                run_simple('0.0.0.0', 8080, app, use_reloader=True, use_debugger=True)





                                share|improve this answer
















                                • 1




                                  I tried your code . it looked like what I was looking for as a test case. I get the following: /usr/local/lib/python3.7/site-packages/flask/app.py", line 1107, in register_blueprint blueprint, self.blueprints[blueprint.name], blueprint.name AssertionError: A name collision occurred between blueprints <flask.blueprints.Blueprint object at 0x1133d8fd0> and <flask.blueprints.Blueprint object at 0x1139184a8>. Both share the same name "assets". Blueprints that are created on the fly need unique names.
                                  – user2945234
                                  Aug 21 at 18:05











                                • Ran into the same problem. I notice that the method worked for one redirection, but not for two redirections to dask apps. I have no clue how the change the assets name.
                                  – Kehlin Swain
                                  Sep 25 at 1:22










                                • It seem that you have to take care of the flask version you use, I had two different experiences when using flask 1.0 and flask 0.12.
                                  – JustInTime
                                  Sep 28 at 7:40












                                up vote
                                3
                                down vote










                                up vote
                                3
                                down vote









                                Ok for those who are lazy enough like me, here is the code



                                from dash import Dash
                                from werkzeug.wsgi import DispatcherMiddleware
                                import flask
                                from werkzeug.serving import run_simple
                                import dash_html_components as html

                                server = flask.Flask(__name__)
                                dash_app1 = Dash(__name__, server = server, url_base_pathname='/dashboard' )
                                dash_app2 = Dash(__name__, server = server, url_base_pathname='/reports')
                                dash_app1.layout = html.Div([html.H1('Hi there, I am app1 for dashboards')])
                                dash_app2.layout = html.Div([html.H1('Hi there, I am app2 for reports')])
                                @server.route('/')
                                @server.route('/hello')
                                def hello():
                                return 'hello world!'

                                @server.route('/dashboard')
                                def render_dashboard():
                                return flask.redirect('/dash1')


                                @server.route('/reports')
                                def render_reports():
                                return flask.redirect('/dash2')

                                app = DispatcherMiddleware(server,
                                '/dash1': dash_app1.server,
                                '/dash2': dash_app2.server
                                )

                                run_simple('0.0.0.0', 8080, app, use_reloader=True, use_debugger=True)





                                share|improve this answer












                                Ok for those who are lazy enough like me, here is the code



                                from dash import Dash
                                from werkzeug.wsgi import DispatcherMiddleware
                                import flask
                                from werkzeug.serving import run_simple
                                import dash_html_components as html

                                server = flask.Flask(__name__)
                                dash_app1 = Dash(__name__, server = server, url_base_pathname='/dashboard' )
                                dash_app2 = Dash(__name__, server = server, url_base_pathname='/reports')
                                dash_app1.layout = html.Div([html.H1('Hi there, I am app1 for dashboards')])
                                dash_app2.layout = html.Div([html.H1('Hi there, I am app2 for reports')])
                                @server.route('/')
                                @server.route('/hello')
                                def hello():
                                return 'hello world!'

                                @server.route('/dashboard')
                                def render_dashboard():
                                return flask.redirect('/dash1')


                                @server.route('/reports')
                                def render_reports():
                                return flask.redirect('/dash2')

                                app = DispatcherMiddleware(server,
                                '/dash1': dash_app1.server,
                                '/dash2': dash_app2.server
                                )

                                run_simple('0.0.0.0', 8080, app, use_reloader=True, use_debugger=True)






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Aug 15 at 9:04









                                JustInTime

                                78131020




                                78131020







                                • 1




                                  I tried your code . it looked like what I was looking for as a test case. I get the following: /usr/local/lib/python3.7/site-packages/flask/app.py", line 1107, in register_blueprint blueprint, self.blueprints[blueprint.name], blueprint.name AssertionError: A name collision occurred between blueprints <flask.blueprints.Blueprint object at 0x1133d8fd0> and <flask.blueprints.Blueprint object at 0x1139184a8>. Both share the same name "assets". Blueprints that are created on the fly need unique names.
                                  – user2945234
                                  Aug 21 at 18:05











                                • Ran into the same problem. I notice that the method worked for one redirection, but not for two redirections to dask apps. I have no clue how the change the assets name.
                                  – Kehlin Swain
                                  Sep 25 at 1:22










                                • It seem that you have to take care of the flask version you use, I had two different experiences when using flask 1.0 and flask 0.12.
                                  – JustInTime
                                  Sep 28 at 7:40












                                • 1




                                  I tried your code . it looked like what I was looking for as a test case. I get the following: /usr/local/lib/python3.7/site-packages/flask/app.py", line 1107, in register_blueprint blueprint, self.blueprints[blueprint.name], blueprint.name AssertionError: A name collision occurred between blueprints <flask.blueprints.Blueprint object at 0x1133d8fd0> and <flask.blueprints.Blueprint object at 0x1139184a8>. Both share the same name "assets". Blueprints that are created on the fly need unique names.
                                  – user2945234
                                  Aug 21 at 18:05











                                • Ran into the same problem. I notice that the method worked for one redirection, but not for two redirections to dask apps. I have no clue how the change the assets name.
                                  – Kehlin Swain
                                  Sep 25 at 1:22










                                • It seem that you have to take care of the flask version you use, I had two different experiences when using flask 1.0 and flask 0.12.
                                  – JustInTime
                                  Sep 28 at 7:40







                                1




                                1




                                I tried your code . it looked like what I was looking for as a test case. I get the following: /usr/local/lib/python3.7/site-packages/flask/app.py", line 1107, in register_blueprint blueprint, self.blueprints[blueprint.name], blueprint.name AssertionError: A name collision occurred between blueprints <flask.blueprints.Blueprint object at 0x1133d8fd0> and <flask.blueprints.Blueprint object at 0x1139184a8>. Both share the same name "assets". Blueprints that are created on the fly need unique names.
                                – user2945234
                                Aug 21 at 18:05





                                I tried your code . it looked like what I was looking for as a test case. I get the following: /usr/local/lib/python3.7/site-packages/flask/app.py", line 1107, in register_blueprint blueprint, self.blueprints[blueprint.name], blueprint.name AssertionError: A name collision occurred between blueprints <flask.blueprints.Blueprint object at 0x1133d8fd0> and <flask.blueprints.Blueprint object at 0x1139184a8>. Both share the same name "assets". Blueprints that are created on the fly need unique names.
                                – user2945234
                                Aug 21 at 18:05













                                Ran into the same problem. I notice that the method worked for one redirection, but not for two redirections to dask apps. I have no clue how the change the assets name.
                                – Kehlin Swain
                                Sep 25 at 1:22




                                Ran into the same problem. I notice that the method worked for one redirection, but not for two redirections to dask apps. I have no clue how the change the assets name.
                                – Kehlin Swain
                                Sep 25 at 1:22












                                It seem that you have to take care of the flask version you use, I had two different experiences when using flask 1.0 and flask 0.12.
                                – JustInTime
                                Sep 28 at 7:40




                                It seem that you have to take care of the flask version you use, I had two different experiences when using flask 1.0 and flask 0.12.
                                – JustInTime
                                Sep 28 at 7:40










                                up vote
                                -2
                                down vote













                                To solve this issue, here is what I did and was successful. This should be documented in official DASH documentation



                                ####################################
                                import dash_core_components as dcc
                                import dash_html_components as html
                                from dash import Dash
                                from dash.dependencies import Input, State, Output

                                from flask import Flask, flash, redirect, render_template, request, session, abort, url_for, json, make_response

                                url_router=''

                                @application.route("/view_tables", methods=['GET','POST'])
                                def view_tabales:
                                # Logic for displaying dashboard using Dash
                                server.layout = html.Div(
                                children=[
                                #division for graph 1
                                html.Div([html.H1(children='Capital Charge'),],className='text-center'),

                                html.Div([html.Div([html.H3(children='''Correlation for assets'''),],className='text-primary'),
                                # define the graph
                                dcc.Graph(
                                id='Delta-graph',
                                figure=
                                'data': [
                                'x': df_delta['Correlation_Level'],
                                'y': df_delta['Capital_Charge'],
                                'type': 'bar',
                                'name': 'Delta',
                                #'domain': 'x': [0, .48],'y': [0, .49],

                                ],
                                # sizes the graph
                                'layout':
                                'title': 'Delta','margin': 'l': 10, 'r': 0, 't': 30, 'b': 10,
                                "height":300,


                                )],className='col-md-4'),
                                url_router = 'Dash(__name__,server=application, url_base_pathname="/dash")'


                                Then you can control which dashboard it is headed from inside flask



                                if url_router !='':
                                server = url_router

                                server.layout = html.Div(children = [html.H1(children = ' MEP dashboard - error 404')])


                                # run the app.
                                if __name__ == "__main__":
                                # Setting debug to True enables debug output. This line should be
                                # removed before deploying a production app.
                                server.secret_key = os.urandom(12)
                                server.run_server(debug=True,port=5000)


                                you can create different functions with different graphs between the Flask code and keep calling the code in dash






                                share|improve this answer
























                                  up vote
                                  -2
                                  down vote













                                  To solve this issue, here is what I did and was successful. This should be documented in official DASH documentation



                                  ####################################
                                  import dash_core_components as dcc
                                  import dash_html_components as html
                                  from dash import Dash
                                  from dash.dependencies import Input, State, Output

                                  from flask import Flask, flash, redirect, render_template, request, session, abort, url_for, json, make_response

                                  url_router=''

                                  @application.route("/view_tables", methods=['GET','POST'])
                                  def view_tabales:
                                  # Logic for displaying dashboard using Dash
                                  server.layout = html.Div(
                                  children=[
                                  #division for graph 1
                                  html.Div([html.H1(children='Capital Charge'),],className='text-center'),

                                  html.Div([html.Div([html.H3(children='''Correlation for assets'''),],className='text-primary'),
                                  # define the graph
                                  dcc.Graph(
                                  id='Delta-graph',
                                  figure=
                                  'data': [
                                  'x': df_delta['Correlation_Level'],
                                  'y': df_delta['Capital_Charge'],
                                  'type': 'bar',
                                  'name': 'Delta',
                                  #'domain': 'x': [0, .48],'y': [0, .49],

                                  ],
                                  # sizes the graph
                                  'layout':
                                  'title': 'Delta','margin': 'l': 10, 'r': 0, 't': 30, 'b': 10,
                                  "height":300,


                                  )],className='col-md-4'),
                                  url_router = 'Dash(__name__,server=application, url_base_pathname="/dash")'


                                  Then you can control which dashboard it is headed from inside flask



                                  if url_router !='':
                                  server = url_router

                                  server.layout = html.Div(children = [html.H1(children = ' MEP dashboard - error 404')])


                                  # run the app.
                                  if __name__ == "__main__":
                                  # Setting debug to True enables debug output. This line should be
                                  # removed before deploying a production app.
                                  server.secret_key = os.urandom(12)
                                  server.run_server(debug=True,port=5000)


                                  you can create different functions with different graphs between the Flask code and keep calling the code in dash






                                  share|improve this answer






















                                    up vote
                                    -2
                                    down vote










                                    up vote
                                    -2
                                    down vote









                                    To solve this issue, here is what I did and was successful. This should be documented in official DASH documentation



                                    ####################################
                                    import dash_core_components as dcc
                                    import dash_html_components as html
                                    from dash import Dash
                                    from dash.dependencies import Input, State, Output

                                    from flask import Flask, flash, redirect, render_template, request, session, abort, url_for, json, make_response

                                    url_router=''

                                    @application.route("/view_tables", methods=['GET','POST'])
                                    def view_tabales:
                                    # Logic for displaying dashboard using Dash
                                    server.layout = html.Div(
                                    children=[
                                    #division for graph 1
                                    html.Div([html.H1(children='Capital Charge'),],className='text-center'),

                                    html.Div([html.Div([html.H3(children='''Correlation for assets'''),],className='text-primary'),
                                    # define the graph
                                    dcc.Graph(
                                    id='Delta-graph',
                                    figure=
                                    'data': [
                                    'x': df_delta['Correlation_Level'],
                                    'y': df_delta['Capital_Charge'],
                                    'type': 'bar',
                                    'name': 'Delta',
                                    #'domain': 'x': [0, .48],'y': [0, .49],

                                    ],
                                    # sizes the graph
                                    'layout':
                                    'title': 'Delta','margin': 'l': 10, 'r': 0, 't': 30, 'b': 10,
                                    "height":300,


                                    )],className='col-md-4'),
                                    url_router = 'Dash(__name__,server=application, url_base_pathname="/dash")'


                                    Then you can control which dashboard it is headed from inside flask



                                    if url_router !='':
                                    server = url_router

                                    server.layout = html.Div(children = [html.H1(children = ' MEP dashboard - error 404')])


                                    # run the app.
                                    if __name__ == "__main__":
                                    # Setting debug to True enables debug output. This line should be
                                    # removed before deploying a production app.
                                    server.secret_key = os.urandom(12)
                                    server.run_server(debug=True,port=5000)


                                    you can create different functions with different graphs between the Flask code and keep calling the code in dash






                                    share|improve this answer












                                    To solve this issue, here is what I did and was successful. This should be documented in official DASH documentation



                                    ####################################
                                    import dash_core_components as dcc
                                    import dash_html_components as html
                                    from dash import Dash
                                    from dash.dependencies import Input, State, Output

                                    from flask import Flask, flash, redirect, render_template, request, session, abort, url_for, json, make_response

                                    url_router=''

                                    @application.route("/view_tables", methods=['GET','POST'])
                                    def view_tabales:
                                    # Logic for displaying dashboard using Dash
                                    server.layout = html.Div(
                                    children=[
                                    #division for graph 1
                                    html.Div([html.H1(children='Capital Charge'),],className='text-center'),

                                    html.Div([html.Div([html.H3(children='''Correlation for assets'''),],className='text-primary'),
                                    # define the graph
                                    dcc.Graph(
                                    id='Delta-graph',
                                    figure=
                                    'data': [
                                    'x': df_delta['Correlation_Level'],
                                    'y': df_delta['Capital_Charge'],
                                    'type': 'bar',
                                    'name': 'Delta',
                                    #'domain': 'x': [0, .48],'y': [0, .49],

                                    ],
                                    # sizes the graph
                                    'layout':
                                    'title': 'Delta','margin': 'l': 10, 'r': 0, 't': 30, 'b': 10,
                                    "height":300,


                                    )],className='col-md-4'),
                                    url_router = 'Dash(__name__,server=application, url_base_pathname="/dash")'


                                    Then you can control which dashboard it is headed from inside flask



                                    if url_router !='':
                                    server = url_router

                                    server.layout = html.Div(children = [html.H1(children = ' MEP dashboard - error 404')])


                                    # run the app.
                                    if __name__ == "__main__":
                                    # Setting debug to True enables debug output. This line should be
                                    # removed before deploying a production app.
                                    server.secret_key = os.urandom(12)
                                    server.run_server(debug=True,port=5000)


                                    you can create different functions with different graphs between the Flask code and keep calling the code in dash







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Apr 26 at 13:48









                                    Mandeep Singh

                                    12




                                    12



























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45845872%2frunning-a-dash-app-within-a-flask-app%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                                        Edmonton

                                        Crossroads (UK TV series)