dash
dash copied to clipboard
[Feature Request] Add optional delay to dcc.Loading()
Is your feature request related to a problem? Please describe. Wrapping a dcc.Loading component around charts and have noticed that the loading animation occurs after every filter change as well as the initial load. While this is good if the filter change takes more than a second or two, we would like it if the component did not kick in if the load time was < 1/2 seconds.
Describe the solution you'd like A delay argument in the dcc.Loading component that will engage the Loader only after a given amount of time.
Describe alternatives you've considered CSS is an alternative, but a delay argument would be helpful for Python devs
@halemade Maybe you can use AntdSpin
in my dash components library fac
, it has a parameter delay
, install it via pip install feffery_antd_components
, here is a simple demo from my documents website:
import feffery_antd_components as fac
fac.AntdSpace(
[
fac.AntdButton('触发耗时0.5秒的回调过程', id='spin-delay-demo-input1', type='primary'),
fac.AntdButton('触发耗时2秒的回调过程', id='spin-delay-demo-input2', type='primary')
]
),
fac.AntdSpin(
fac.AntdText('0.5秒回调 nClicks: 0', id='spin-delay-demo-output1', strong=True),
delay=1000,
text='回调中'
),
fac.AntdSpin(
fac.AntdText('2s回调 nClicks: 0', id='spin-delay-demo-output2', strong=True),
delay=1000,
text='回调中'
)
...
@app.callback(
Output('spin-delay-demo-output1', 'children'),
Input('spin-delay-demo-input1', 'nClicks'),
prevent_initial_call=True
)
def spin_delay_callback_demo1(nClicks):
import time
time.sleep(0.5)
return f'0.5秒回调 nClicks: {nClicks}'
@app.callback(
Output('spin-delay-demo-output2', 'children'),
Input('spin-delay-demo-input2', 'nClicks'),
prevent_initial_call=True
)
def spin_delay_callback_demo2(nClicks):
import time
time.sleep(2)
return f'2秒回调 nClicks: {nClicks}'
I second this.
The loading component is basically incompatible with some other components (for instance dash_bootstrap_components.TextArea or dcc.Input on beefier applications) since every time you begin typing you may trigger a change in loading state for a brief moment, and then you're cursor is no longer focused on the element you were typing in .... as an example.
closed by #2760