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

Figure doesn't load from callback unless another dash_core_component is in the layout #424

Closed
mbkupfer opened this issue Oct 9, 2018 · 2 comments

Comments

@mbkupfer
Copy link

mbkupfer commented Oct 9, 2018

I was trying to create a workable example to solve this community question, but I could only make it work with another dcc component inside. Here is the example:

import time

import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html


loading_component = html.H1(
    style={},
    children='Loading...'
)

app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Input(), # callback doesn't work without this line

    html.Div(id='live-graph-container', children=[
        loading_component
    ]),
    # Arbitrary element to fire the callback below
    html.P(
        id='trigger-live-chart',
        children=''),
])

@app.callback(Output('live-graph-container', 'children'),
    [Input('trigger-live-chart','children')])
def generate_live_chart(_):
    time.sleep(3) # simmulate 3 seconds of data processing
    return dcc.Graph(
        id='live-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )


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

If you remove that dcc.Input() line, the program still runs, but you are just stuck with the loading text. Is this happening for others when they try to use it, or just me? Any thoughts on why this is occurring?

For reference, here are my plotly related packages version:

dash                   0.28.2
dash-core-components   0.33.0
dash-html-components   0.13.2
dash-renderer          0.14.1
plotly                 3.3.0
@chriddyp
Copy link
Member

chriddyp commented Oct 9, 2018

Thanks for reporting and for helping out in the community forum! I believe that this is a repeat of plotly/dash-renderer#46

@mbkupfer
Copy link
Author

mbkupfer commented Oct 9, 2018

Sounds good and glad to help out!

Seems like the work around is very simple, but good to know that this issue exists. Perhaps adding an exception that parses the layout after parsing callbacks would be a nice warning to print out for those not in the know.

@T4rk1n T4rk1n self-assigned this Oct 31, 2018
Dash - A Pleasant and Productive Developer Experience automation moved this from To do to Done Nov 6, 2018
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this issue May 28, 2021
HammadTheOne pushed a commit that referenced this issue Jul 23, 2021
AnnMarieW pushed a commit to AnnMarieW/dash that referenced this issue Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants