this is my run file:
import dash
import dash_html_components as html
import dash_core_components as dcc
from apps import app1, app2
app = dash.Dash()
def update_layout():
return html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
app.layout = update_layout
@app.callback(dash.dependencies.Output('page-content', 'children'),
[dash.dependencies.Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/apps/app1':
return app1.layout
elif pathname == '/apps/app2':
return app2.layout
if __name__ == '__main__':
app.run_server(debug=True)
and also i have for example
app1
import dash
import dash_html_components as html
import datetime
def update_layout():
return html.Div('app1 {}'.format(datetime.datetime.now().strftime('%y-%m-%d %H:%M:%S')))
layout = update_layout
and app2
import dash
import dash_html_components as html
import datetime
def update_layout():
return html.Div('app2 {}'.format(datetime.datetime.now().strftime('%y-%m-%d %H:%M:%S')))
layout = update_layout
Is it possible to somehow to assign a function app1.layout and app2.layout to initiate updates on page load?
With provided approach now i’m getting
File “/usr/lib/python3.5/json/encoder.py”, line 179, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <function update_layout at 0x7fa46553aa60> is not JSON serializable