-
Notifications
You must be signed in to change notification settings - Fork 151
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
[Feat] Improve background color and loading spinner on loading layout #598
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good but it doesn't actually seem to work for me... Maybe we're being too fancy with the spinner and should just change the colour of the background of the screen. Just glancing at the dev tools, maybe we need to worry about _dash-loading-callback
instead/as well as _dash-loading
? Not sure.
https://github.com/user-attachments/assets/d83b3725-c219-4219-93f2-6c8366e3d442
Hmmm, I guess this is because of the Dash pages callback that runs to update the page contents 🤔 Maybe we need to do this instead or as well? https://community.plotly.com/t/displaying-loading-screen-when-pages-container-is-loading/72109 |
What do you mean by this @antonymilne? I don't fully follow 😄 For me the dev example worked but there was also only one page. For me it looked like it works fine. What potential issues do you anticipate? |
Would eventually rename to |
The thing I'm not sure about basically comes down to "where do I put my |
I've put it inside the chart. It will only extend the loading screen for a few seconds, but sufficiently enough to see how it looks like. At least it was enough for me to edit the CSS above 😄 It should also be better visible if we implement the code suggestion above :) I made it a bit bigger and placed it at the center of the page. The animation I think is also slower. Would still like to have @pruthvip15 take a look at the CSS on the code suggestion above.
|
…to feat/improved_load_CSS
for more information, see https://pre-commit.ci
So I had a similar problem! I never really resolved it, but it was also hard to track down the root cause because most of that work was done on a train where it struggled even to load the static google assets 😂 . In a pure dash app it is easy to make the layout loading function have a sleep timer as in this example What I do is I pause the app in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work, and a great team effort! 🙌 The white loading screen has always annoyed me so nice to have it gone 🥳
I spoke with @maxschulz-COL about this already - there's still a small white flash in between the loading spinner disappearing and the page appearing. I don't know whether it will be possible to get rid of that, but do give it a quick go and see if targeting html
can do it without breaking the page after it's finished loading.
To clarify some of the things I said earlier and also explain what's happening here, since it is pretty confusing as there's many different things that load on our page, and this will become important to understand in discussions we'll have soon about actions on-page-load etc.
This is what's in the HTML of a Dash app:
<div id="react-entry-point">
STUFF
</div>
The order of page loading is something like this:
- Dash runs
app.layout = dashboard.build()
on backend to setapp.layout
, which is passed to Dash renderer - while this is happening,
STUFF
above is<div class="_dash-loading">...</div>
- when it's finished,
STUFF
becomes the real page content, i.e. what's returned byapp.layout
- for us, this
app.layout
is anhtml.Div
that contains a few things includingdash.page_container
dash.page_container
is initially an empty placeholder but populated by the Dash pages callback- for us, this
page_container
setslayout=partial(self._make_page_layout, page)
, which ends up callingpage.build
- since this is set as a function, every time you refresh the page, this layout function is re-run (but the overall
dashboard.build
is not) - when you change page, the Dash pages callback executes but does not do a full page refresh, so steps 1 and 2 above do not apply
- for us it's even more complicated 😅 Because the page that gets loaded by the Dash pages callback just contains blank placeholders for the graph and table/grid (not currently the case, but ideally would be) and those then get populated with the real data in the
on_page_load
action
The white "Loading..." screen only shows during steps 1 and 2 above and not after that. Hence the correct way to get this to show is to delay these two steps. Putting a time.sleep
in page.build
like I was trying doesn't do it, and neither does putting it inside the graph function like @huong-li-nguyen does above. These both delay steps that happen after 1/2 and do not affect the "Loading..." screen.
There's at least 3 ways to delay steps 1/2:
- pause the frontend execution with a debugger like @maxschulz-COL did
- set
app.layout = dashboard.build
works for a pure Dash app but not for us it seems - use hooks to delay the Dash renderer like this (not well documented but see Feature: Add hooks for layout "pre" and "post" plotly/dash#2630):
# The code to sleep for 5 seconds is not good JS but it works fine for this example
hooks = {
"layout_pre": """
() => {
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < 5000);
console.log("pre")
}
""",
"layout_post": """
(response) => {
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < 5000);
console.log("post")
console.log(response)
}
""",
}
self.dash = dash.Dash(**kwargs, use_pages=True, pages_folder="", title="Vizro", hooks=hooks)
I just went through these docs, which might be helpful. Firstly, you can customize the "Loading..." message. Referring back to @pruthvip15's suggestion, instead of making the message transparent, we should remove it if possible. This can be done via:
You can also customize the Dash index page: https://dash.plotly.com/external-resources#customizing-dash's-html-index-template I'm not sure if this will help in this specific case, but you could potentially make it dark by ensuring some of your CSS loads before Dash's CSS. However, I'm not sure if it's worth the effort. The transition from the white to dark loading screen only lasts a split second, so it doesn't bother me that much. |
@huong-li-nguyen AIUI I think we should set (Yes this is all very confusing - this is what I meant above that there's many different things in Dash that are to do with loading.) Agree that editing the index template isn't worth doing just to try and eliminate the small white flash - it also doesn't bother me much. So I would only do this if it's a simple bit of extra CSS like we're doing here, not if it's any harder than that. |
… app building stages
for more information, see https://pre-commit.ci
…to feat/improved_load_CSS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the white flash has gone?! Amazing work!! 🙌
for more information, see https://pre-commit.ci
Description [edited]
This PR contains:
Loading...
text to a loading spinnerGiven that we do not have access to our variables yet, it was decided to choose a hard-coded dark mode color in
root
.Screenshot
Notice
I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":