[go: up one dir, main page]

Skip to content
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

dcc.Loading is not accessible by DOM in Dash 2.18.2 #3097

Open
Kissabi opened this issue Nov 29, 2024 · 0 comments
Open

dcc.Loading is not accessible by DOM in Dash 2.18.2 #3097

Kissabi opened this issue Nov 29, 2024 · 0 comments

Comments

@Kissabi
Copy link
Kissabi commented Nov 29, 2024

Description

The dcc.Loading component's children and elements within custom_spinner are not accessible via document.getElementById in clientside callbacks when using Dash 2.18.2. This prevents direct DOM manipulation within these elements.

Steps to Reproduce

The following minimal example demonstrates the issue:

from dash import Dash, html, Input, Output, dcc

app = Dash(prevent_initial_callbacks=True)

app.layout = html.Div([
    html.Button("Button 1", id="btn1"),
    html.Button("Button 2", id="btn2"),
    html.Button("Button 3", id="btn3"),
    dcc.Loading(html.P(id="logA"), overlay_style={"visibility":"visible", "opacity": 0.5, "backgroundColor": "#000"}, custom_spinner=html.Div(id="logB"), id="logC")
])

# Works (accessing direct child of layout)
app.clientside_callback(
    """
    async function(){
        const content = document.getElementById("logA");

        if (!content) {
            console.error("content element not found!");
            return;
        }
		
        await new Promise(r => setTimeout(r, 10000)); 
        return "Test";
    }
    """,
    Output("logA", "children"),
    Input("btn1", "n_clicks"),
    prevent_initial_call=True
)

# Does not work (accessing custom_spinner element)
app.clientside_callback(
    """
    function(){
        const content = document.getElementById("logB");

        if (!content) {
            console.error("content element not found!");
            return;
        }
        
        return "loading test...";
    }
    """,
    Output("logB", "children"),
    Input("btn1", "n_clicks"),
    prevent_initial_call=True
)

# Does not work (accessing the Loading component itself)
app.clientside_callback(
    """
    function(){
        const content = document.getElementById("logC");

        if (!content) {
            console.error("content element not found!");
            return;
        }
        
        return "loading test...";
    }
    """,
    Output("logC", "children"),
    Input("btn1", "n_clicks"),
    prevent_initial_call=True
)

if __name__ == '__main__':
    app.run_server(debug=True)

Expected Behavior

All elements with assigned IDs (logA, logB, and logC) should be accessible via document.getElementById within clientside callbacks.

Actual Behavior

Only logA (the direct child of the layout, outside custom_spinner and not the dcc.Loading component itself) is accessible. logB (inside custom_spinner) and logC (the dcc.Loading component) are not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant