2

I will briefly explain my current situation.

app1 & app2 are dash app and reloaded every 5 seconds. And basically, everything works fine. But when I move to app2 tab by clicking the app2 button on my bootstrap navigation menu, I still can see the message below.

127.0.0.1 - - [21/Jan/2018 01:17:00] "POST /app1/_dash-update-component HTTP/1.1" 200 -
127.0.0.1 - - [21/Jan/2018 01:17:00] "POST /app2/_dash-update-component HTTP/1.1" 200 -
127.0.0.1 - - [21/Jan/2018 01:17:03] "POST /app1/_dash-update-component HTTP/1.1" 200 -
127.0.0.1 - - [21/Jan/2018 01:17:03] "POST /app2/_dash-update-component HTTP/1.1" 200 -
127.0.0.1 - - [21/Jan/2018 01:17:05] "POST /app1/_dash-update-component HTTP/1.1" 200 -

The problem is, app1 seems to keep refreshing even though I've already left the app1 menu.

Actually, I'm lost here and nothing comes to my mind anymore. Should I change the way combine dash apps and flask app? or is there any brilliant way to pause app1 whilst the user watching app2 dash app?

Thank you.

app_main.py

from werkzeug.wsgi import DispatcherMiddleware
from flask_bootstrap import Bootstrap

import app1
import app2

flask_app = flask.Flask(__name__)

server = DispatcherMiddleware(flask_app, {
    '/app1': app1.app_dash.server,
    '/app2': app1.app_dash.server,
})

Bootstrap(flask_app)

index.html

...
<div id="app1" class="tab-pane fade">
    <object data="/basic_chart"></object>

</div>
<div id="app2" class="tab-pane fade">
    <object data="/balance_chart"></object>

</div>
...

app1.py

...
app_dash.layout = html.Div([
    dcc.Interval(
        id='interval-component',
        interval=5e3,  # in milliseconds
        n_intervals=0
    ),

    html.Div([
        dcc.Graph(
            id='graph_stream',
        ),
    ]),
...
su79eu7k
  • 7,031
  • 3
  • 34
  • 40

1 Answers1

1

Instead of using DispatcherMiddleware and a route like /app1 you could use dash_core_components.Location and dash_core_components.Link to develop a single-page app.

See Multi-Page Apps and URL Support.

jackdbd
  • 4,583
  • 3
  • 26
  • 36