Hereās an example of delay
.delay {
position: relative;
}
.delay::after {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
/* min and max vals in case children (content)
* does not exist at all until the callback
* processes */
min-height: 18px;
min-width: 181px;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.4);
animation: fadeout 2s forwards;
}
.delay[data-dash-is-loading="true"]::after{
content: "";
display: block;
background-color: rgba(255, 255, 255, 0.4);
/* 2s delay + 0.5s transition */
animation: fadein 2.5s forwards;
}
@keyframes fadein {
0% { opacity: 0; }
/*
* as above, the the entire transition is 2.5 seconds long.
* so, to "delay" the loading screen for 2 seconds,
* keep it "hidden" (opacty: 0) for 80% of the
* total of transition time: 0.8 * 2.5 = 2 seconds
*/
80% { opacity: 0; }
100% { opacity: 1; }
}
@keyframes fadeout {
from { opacity: 1;}
to { opacity: 0;}
}
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objs as go
import time
app = dash.Dash(__name__)
style = {'width': 300, 'marginLeft': 'auto', 'marginRight': 'auto'}
app.layout = html.Div(
children=[
html.Div(style=style, children=[
dcc.Input(id="input-1", value="new value"),
html.Div("old value", className='delay', id="output-1")
]),
html.Div(style=style, children=[
dcc.Input(id="input-2", value="input causes loading"),
html.Div(dcc.Graph(
figure={
'data': [
go.Scatter(
x=[1, 2, 3, 4, 5],
y=[1, 5, 1, 3, 4],
)
]
}
), className="delay", id="output-2")]),
]
)
@app.callback(
Output("output-1", "children"),
[Input("input-1", "value")])
def input_triggers_spinner(value):
time.sleep(5)
return value
@app.callback(
Output("output-2", "children"),
[Input("input-2", "value")])
def input_triggers_nested(value):
time.sleep(5)
return dcc.Graph(figure={
'data': [
go.Scatter(
x=[1, 2, 3, 4, 5],
y=[1, 5, 1, 3, 4],
marker = dict(
size = 10,
color = 'rgba(152, 0, 0, .8)',
line = dict(
width = 2,
color = 'rgb(0, 0, 0)'
)
)
)
],
'layout': {'title': value}
})
if __name__ == "__main__":
app.run_server(debug=True)