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

[BUG] id passed through dcc.Loading not visible in DOM #2878

Closed
huong-li-nguyen opened this issue Jun 7, 2024 · 4 comments
Closed

[BUG] id passed through dcc.Loading not visible in DOM #2878

huong-li-nguyen opened this issue Jun 7, 2024 · 4 comments

Comments

@huong-li-nguyen
Copy link

huong-li-nguyen commented Jun 7, 2024

Describe your context
Hello guys 👋

I am currently trying to pass an id to the dcc.Loading component or its parent container and I would like the id to be visible in the DOM such that I can target the CSS of the components inside the dcc.Loading via ID.

Please provide us your environment, so we can easily reproduce the issue.

  • replace the result of pip list | grep dash below
dash                      2.17.0
dash-bootstrap-components 1.5.0
dash-core-components      2.0.0
dash-html-components      2.0.0
  • if frontend related, tell us your Browser, Version and OS

    • OS: [e.g. iOS]
    • Browser: Chrome
    • Version [e.g. 22]

Describe the bug
Let's take the example app below - what I would have expected is that there would be an html div visible with a className="loading" and an id="loading-id". However, if I provide the className="loading" I see a div but it does not have the className="loading" in the DOM nor does it have the id="loading-id" in the DOM.

When I switch this to parent_className="loading", now I see a div with the className="loading", but I cannot attach an id to this parent container.

I am not a react expert, but from the source I can see that the id doesn't seem to be passed on in the return of the react component and is therefore not visible in the DOM? Is there any reason for that?

return (
<div
style={{position: 'relative', ...parent_style}}
className={parent_className}
>
<div

from dash import Dash, html, dcc, callback, Output, Input
import plotly.express as px
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')

app = Dash()

app.layout = [
    html.H1(children='Title of Dash App', style={'textAlign':'center'}),
    dcc.Dropdown(df.country.unique(), 'Canada', id='dropdown-selection'),
    dcc.Loading(dcc.Graph(id='graph-content'), color='grey', id="loading-id", parent_className="loading")
]

@callback(
    Output('graph-content', 'figure'),
    Input('dropdown-selection', 'value')
)
def update_graph(value):
    dff = df[df.country==value]
    return px.line(dff, x='year', y='pop')

if __name__ == "__main__":
    app.run(debug=True)

Expected behavior

I would expect the id being passed on to the react component and visible in the DOM, so having a <div class="loading" id="loading-id" visible in the DOM.

Screenshots
Screenshot 2024-06-07 at 12 29 36

@huong-li-nguyen huong-li-nguyen changed the title [BUG] id not passed through react component of dcc.Loading [BUG] id passed through dcc.Loading not visible in DOM Jun 7, 2024
@T4rk1n
Copy link
Contributor

T4rk1n commented Jun 7, 2024

I don't think there's a particular reason for it to be missing, it should be added.

@huong-li-nguyen
Copy link
Author

I can try to fix it :) Seems like it's just a one-line change?

@T4rk1n
Copy link
Contributor

T4rk1n commented Jun 7, 2024

Seems like it's just a one-line change?

Yes, maybe two lines, adding the id prop in the function arguments then on the div.

@T4rk1n
Copy link
Contributor

T4rk1n commented Jun 18, 2024

Fixed by #2888

@T4rk1n T4rk1n closed this as completed Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants