Skip to content

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

Closed

Description

@mbkupfer

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

Activity

  1. chriddyp commented on Oct 9, 2018

    @chriddyp
    Member

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

  2. mbkupfer commented on Oct 9, 2018

    @mbkupfer
    Author

    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.

  3. self-assigned this
    on Oct 31, 2018
  4. added a commit that references this issue on May 28, 2021
  5. added a commit that references this issue on Jul 23, 2021
  6. added a commit that references this issue on Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions