# Manual dcc.Loading component

**URL:** <https://community.plotly.com/t/manual-dcc-loading-component/68886>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [October 13, 2022, 6:56pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886 "2022-10-13T18:56:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkunstle](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkunstle](https://community.plotly.com/u/jkunstle)\
**Post date:** [October 13, 2022, 6:56pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/1 "2022-10-13T18:56:24Z")

</div>

Right now, a dcc.Loading component is in the ‘Loading’ state while the components that it wraps are waiting for a response from the server. Looking at the source code, the description is:

“A Loading component that wraps any other component and displays a spinner until the wrapped component has rendered.”

In my use-case, I would like to enable and disable this component manually based on context. Some responses from the server are fast enough that the ‘loading’ animation just flashes so it should be disabled then, but for longer-lasting responses (it is known from context which responses will be long or short) it should be enabled.

Does anyone know if there’s a 3rd party component that solves this problem, or if there’s a work-around with the existing component? It takes the ‘is\_loading’ dictionary which is a lead but even playing around with it I can’t find the right workflow.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [October 13, 2022, 7:24pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/2 "2022-10-13T19:24:05Z")

</div>

Hello @jkunstle,

Yes, you can trigger displaying manually of a loading spinner, although it is more tricky than just the regular use case.

For example, I have a spinner called “hex-loading”, in the javascript I tell it when to hide and when to show. I have no children associated with it.

---

<div class="post-metadata">

**Author:** ![jkunstle](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkunstle](https://community.plotly.com/u/jkunstle)\
**Post date:** [October 13, 2022, 7:32pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/3 "2022-10-13T19:32:48Z")

</div>

Hey @jinnyzor!

That’s great info, would you mind please linking me to a page that supports that? I’d love to learn from how you did it.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [October 13, 2022, 7:40pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/4 "2022-10-13T19:40:37Z")

</div>

Sure, here you go:

> [@Show-and-Tell - Dash Loading Spinners](https://community.plotly.com/t/show-and-tell-dash-loading-spinners/54436):
>
> Hi all! I just wanted to share a new Dash component library I’ve recently made called dash-loading-spinners which is full of different spinners to use in place of the basic dcc.Loading component. You can read the docs [here](https://dash-loading-spinners.sproodlebuzz.co.uk/) which includes examples of the spinners included. I’ve added it to PyPI so can be installed using pip: pip install dash-loading-spinners Hope you enjoy it. Feel free to contribute, make suggestions etc via [GitHub](https://github.com/glsdown/dash-loading-spinners). It’s my first python package, so there are likely to be thi…

Docs:

[https://dash-loading-spinners.sproodlebuzz.co.uk/](https://dash-loading-spinners.sproodlebuzz.co.uk/)

Example of it in code:

```auto
dls.Custom(
                              svg="<object data='../assets/hex-loading.svg' type='image/svg+xml'"
                                  " style='position: relative; top: -50px;"
                                  "height: 95%; width: 95%;'></object>",
                              id='hex-loading',
                              show_initially=True,
                              children=[]),

```

You’ll have to mess around with the style in order to get it in the right spot.

css:

```auto
#hex-loading {
        top: 0px;
        height: 100vh;
        width: 100vw;
        position: absolute;
        z-index: 900;
        background-color: rgba(255,255,255,0.7);
    }

```

Then in javascript, I use jquery cause its shorter 😉 😛

```auto
window.fetch = new Proxy(window.fetch, {
    apply(fetch, that, args) {
        // Forward function call to the original fetch
        const result = fetch.apply(that, args);

        // Do whatever you want with the resulting Promise
        result.then((response) => {

            if (args[0] == '/_dash-update-component') {
                if (meetscriteria) { $("#hex-loading").hide() }
         }
         });

        return result;
    }
});
        

```

Then whenever you want to show it:

```auto
$("#hex-loading").show()

```

---

<div class="post-metadata">

**Author:** ![jkunstle](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkunstle](https://community.plotly.com/u/jkunstle)\
**Post date:** [October 13, 2022, 7:47pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/5 "2022-10-13T19:47:28Z")

</div>

This is very exciting to see, we’ve been hoping to find something like this for a while.

Which project is this a part of? We’re hoping to find examples of more sophisticated apps written with Dash so we can learn from the design-patterns that they implement, and it seems like code like this would have to come from a project that’s more sophisticated from a Javascript perspective than our own.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [October 13, 2022, 7:57pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/6 "2022-10-13T19:57:29Z")

</div>

😊

Sorry, its nots open-source… And its not completed either. I dont know if anything else is out there which approaches it the same way, I’ve kinda pulled it together from different sources as I’ve learned.

The biggest hurdle to get over, is understanding the issue between the need to synchronization between the server and the client.

Example:  
If you manipulate a dom via JS on the client side, you cannot update the dom from the server side any more. Neither can you see the new information on the server.

Fixes:  
Do clientside callbacks that query the new information to pass it along, the new data cannot be used as the input, but rather a button and then inside the javascript function, you pull the updated info and pass it to the response.

This applies to anything you’ve manipulated, dcc.Stores, graphs, etc. I’ve even had a graph stop getting updates because I added an event listener for plotly\_click and plotly\_select. 😛

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [October 13, 2022, 8:43pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/7 "2022-10-13T20:43:56Z")

</div>

Also, one other thing to keep in mind, its built upon flask, so you can do some stuff with the flask side as well.

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [October 13, 2022, 9:55pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/8 "2022-10-13T21:55:08Z")

</div>

@jinnyzor is describing some cool stuff - but back to @jkunstle 's original question, if you are using the dash-bootstrap-components library, you could try the `dbc.Spinner` – it has these two props that might help:

> **`delay_hide`** (_number_; default `0`): When using the spinner as a loading spinner, add a time delay (in ms) to the spinner being removed to prevent flickering.

> **`delay_show`** (_number_; default `0`): When using the spinner as a loading spinner, add a time delay (in ms) to the spinner being shown after the loading\_state is set to True.

[https://dash-bootstrap-components.opensource.faculty.ai/docs/components/spinner/](https://dash-bootstrap-components.opensource.faculty.ai/docs/components/spinner/)

---

<div class="post-metadata">

**Author:** ![jkunstle](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkunstle](https://community.plotly.com/u/jkunstle)\
**Post date:** [October 14, 2022, 2:23pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/9 "2022-10-14T14:23:58Z")

</div>

This info will undoubtedly come in handy once our app is a bit more sophisticated, thanks so much for taking the time to describe your solution and the other fixes you’ve had to Dash problems.

---

<div class="post-metadata">

**Author:** ![jkunstle](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkunstle](https://community.plotly.com/u/jkunstle)\
**Post date:** [October 14, 2022, 2:24pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/10 "2022-10-14T14:24:40Z")

</div>

Yes absolutely, ultimately that’s going to be our next learning path- how to customize the boilerplate Dash experience with our own Flask-centric logic.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [October 14, 2022, 2:25pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/11 "2022-10-14T14:25:49Z")

</div>

If you already use Flask, you can import that flask app as the server for the dash app.

---

<div class="post-metadata">

**Author:** ![jkunstle](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkunstle](https://community.plotly.com/u/jkunstle)\
**Post date:** [October 14, 2022, 2:26pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/12 "2022-10-14T14:26:02Z")

</div>

Oh that’s an excellent idea, one could absolutely use this to delay-show for an arbitrarily long time for some cases, and to 0 for other cases. Thanks so much for the lead!

---

<div class="post-metadata">

**Author:** ![jkunstle](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkunstle](https://community.plotly.com/u/jkunstle)\
**Post date:** [October 14, 2022, 2:27pm UTC](https://community.plotly.com/t/manual-dcc-loading-component/68886/13 "2022-10-14T14:27:03Z")

</div>

Oh very interesting, I’ll look for some examples of that design pattern, that sounds very useful.
