Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Live Updates with mutipage app-

I’ve got a multipage app that isn’t updating upon refresh. I’ve recreated a very basic example.

index.py →

import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from test_page import overviewLayout
from app import app

def serve_layout():
    tmpLayout = html.Div([
    dcc.Location(id='url', refresh=False),
    html.Div(id='main-content1')])
    return tmpLayout


app.config.suppress_callback_exceptions= True
app.layout = serve_layout


@app.callback(Output('main-content1', 'children'),
              [Input('url', 'pathname')])
def display_page(pathname):
    if pathname=='/':
        return overviewLayout
    else:
        return html.H3('COMING SOON')

if __name__ == '__main__':
    app.run_server(debug=False,port=8051,host=('0.0.0.0'))

app.py->

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

test_page.py →

overviewLayout = [
    html.H1('The time is: ' + str(datetime.datetime.now()))

]

try changing overviewLayout to be a function. currently it is a variable which means it’s imported and evaluated when you run python index.py rather than when you load the page and the callback is evalauated.

1 Like

Ok, thanks. So that worked, but it’s now making load times pretty slow (which is expected). Can you shed a bit of light on what is happening? If I wrap my main layout in a function (the serve_layout() function) it will refresh when I refresh the browser, but is the function actually re-executing? Because it will seemingly still point at old data unless I wrap the overviewLayout into a function as well. Am I understanding that correctly?