This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Loading component does not render on first load if using dcc.Location #488
Copy link
Copy link
Open
Description
The loading component does not show when the page is first loaded if using dcc.Location to change the page layout. The first example below doesn't use dcc.Location while the second does. Maybe something do with the elements not being in the initial layout?
Version installed with dash==0.39.0
# -*- coding: utf-8 -*-
import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objs as go
import time
import numpy as np
from dash.dependencies import Input, Output, State
app = dash.Dash(__name__)
app.scripts.config.serve_locally = True
app.config['suppress_callback_exceptions']=True
app.layout = html.Div([
html.Div([
dcc.Loading(
id="loading-1",
children=[html.Div(id='figure-container')],
type="circle"),
html.Button(id="input-1", children='Input triggers nested spinner')
], style={'width': 400}),
html.Div([
dcc.Loading(
id="loading-2",
children=[html.Div([dcc.Graph(id='figure-2')])],
type="circle"),
html.Button(id="input-2", children='Input triggers nested spinner')
], style={'width': 400})
])
@app.callback(Output("figure-container", "children"), [Input("input-1", "n_clicks")])
def input_triggers_nested(n_clicks):
time.sleep(2)
fig = go.Scatter(
x=np.random.random(size=10),
y=np.random.random(size=10)
)
return dcc.Graph(figure=dict(data=[fig]), id='figure-1')
@app.callback(Output("figure-2", "figure"), [Input("input-2", "n_clicks")])
def input_triggers_nested(n_clicks):
time.sleep(2)
fig = go.Scatter(
x=np.random.random(size=10),
y=np.random.random(size=10)
)
return dict(data=[fig])
if __name__ == "__main__":
app.run_server(debug=True, port=8053)
# -*- coding: utf-8 -*-
import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objs as go
import time
import numpy as np
from dash.dependencies import Input, Output, State
app = dash.Dash(__name__)
app.scripts.config.serve_locally = True
app.config['suppress_callback_exceptions']=True
app.layout = html.Div([
dcc.Location(id='url'),
html.Div(id='page-body')
])
def make_layout(pathname):
return html.Div([
html.Div([
dcc.Loading(
id="loading-1",
children=[html.Div(id='figure-container')],
type="circle"),
html.Button(id="input-1", children='Input triggers nested spinner')
], style={'width': 400}),
html.Div([
dcc.Loading(
id="loading-2",
children=[html.Div([dcc.Graph(id='figure-2')])],
type="circle"),
html.Button(id="input-2", children='Input triggers nested spinner')
], style={'width': 400})
])
@app.callback(Output('page-body', 'children'),
[Input('url', 'pathname')])
def page(pathname):
return make_layout(pathname)
@app.callback(Output("figure-container", "children"), [Input("input-1", "n_clicks")])
def input_triggers_nested(n_clicks):
time.sleep(2)
fig = go.Scatter(
x=np.random.random(size=10),
y=np.random.random(size=10)
)
return dcc.Graph(figure=dict(data=[fig]), id='figure-1')
@app.callback(Output("figure-2", "figure"), [Input("input-2", "n_clicks")])
def input_triggers_nested(n_clicks):
time.sleep(2)
fig = go.Scatter(
x=np.random.random(size=10),
y=np.random.random(size=10)
)
return dict(data=[fig])
if __name__ == "__main__":
app.run_server(debug=True, port=8053)
ostwalprasad
Metadata
Metadata
Assignees
Labels
No labels