-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML component showing running status #90
Comments
Great question @RLstat . There isn't a great way to do this with |
A progress spinner component for the entire app and/or individual elements would be great. I was just starting to think about the need for precisely this in the app I'm building. |
I had the same problem and came up with the following workaround. There's a very sleek unobtrusive JavaScript progress bar rstacruz/nprogress, which is also extremely easy to use - you just need to call Putting all of it together, I ended up with the following: # Only used for $(document).ready callback - you can replace with plain JavaScript if you prefer
app.scripts.append_script({"external_url": "http://code.jquery.com/jquery-3.2.1.min.js"})
# NProgress is hosted on CDN
app.scripts.append_script({"external_url": "https://cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"})
app.css.append_css({"external_url": "https://cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css"})
# This can be replaced with a simpler version mentioned above if you don't need to support old browsers
app.scripts.append_script({"external_url": "https://jsfiddle.net/nirvana_msu/bov2y1o0/show_js/"}) Finally, we need to register the following JavaScript. You can check this thread for advice on how to publish local assets. $(document).ready(function () {
// We hook into Fetch API events using monkey-patched version of fetch
fetchIntercept.register({
request: function (url, config) {
NProgress.start();
return [url, config];
},
response: function (response) {
NProgress.done();
return response
}
});
}); It works quite well, but still far from perfect. Since we're hooking into |
And a bonus - you can give feedback to a user if there's been an error processing the update by changing progress bar color to red, making it full width, and keeping on screen until the next request fires. I'm using Javascript: // Need to track number of active requests to update progress when last one finishes
var fetchRequestCount = 0;
$(document).ready(function () {
// We hook into Fetch API events using monkey-patched version of fetch
fetchIntercept.register({
request: function (url, config) {
fetchRequestCount++;
// Reset progress bar in case there was an error previously
$('html').removeClass('nprogress-error');
NProgress.done();
NProgress.start();
return [url, config];
},
response: function (response) {
fetchRequestCount--;
if (fetchRequestCount == 0) { // don't update progress bar unless last request finished loading
if (!response.ok) {
$('html').addClass('nprogress-error'); // Highlight the fact there's been an error
NProgress.set(0.999); // keep the bar visible, full length (indicating request has finished)
} else {
NProgress.done();
}
}
return response
}
});
}); Css: .nprogress-error #nprogress .spinner {
display: none !important;
}
.nprogress-error #nprogress .bar {
background: red !important;
} |
Some updates for loading state here: https://community.plot.ly/t/mega-dash-loading-states/5687 |
Closing in favor of #267, a proposal for adding loading states to the underlying component framework. |
Hi, dash users and developers,
I have a program that takes some time to run upon update with callback. I want to have a html component showing it is "Running" or "Completed".
I was trying to do as following:
However, it suffers from two problems:
Please help me out either with the two problems or the original goal.
Thanks!!
The text was updated successfully, but these errors were encountered: