Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Dash dashboard won't run when callback is included

$
0
0

Hello everyone! I’m currently using JupyterDash within a Jupyter notebook. My current issue is that I’m having a hard time incorporating a functioning Plot.ly go.FigureWidget with my Dash dashboard.

Information about go.FigureWidget

  • Within this notebook, I have a go.FigureWidget plot with two scatter plots
  • This go.FigureWidget is updated every minute within a separate cell
  • These updates successfully display within the cell containing the code below
fig = go.FigureWidget(layout=go.Layout(title=go.layout.Title(text="Live BTC"),
                                      )
                     )
fig.add_scatter(name='actual')
fig.add_scatter(name='prediction')

Information about the Dash Dashboard

  • My goal is to incorporate the above go.FigureWidget within a Dash dashboard
  • I was able to display the graph with an external dashboard, but I had to physically refresh the page to get the updates
  • As a result, I decided to implement dcc.Interval so that the dashboard would update on its own
  • However, I’m unable to benefit from the dcc.Interval because I’m having issues with @app.callback
  • As soon as I uncomment the @app.callback lines, I get “SyntaxError: invalid syntax”
# Build App
app = JupyterDash(__name__)
app.layout = html.Div([
    html.H1("My dashboard", style= {'text-align':'center', 'font-family':'Viga'}),
    
    #Side-by-Side graphs
    html.Div(children = [
        dcc.Graph(id='g1', figure={'data': [{'y': [1, 2, 3]}]}, style={'display': 'inline-block'}),
        dcc.Graph(id='g2', figure={'data': [{'y': [1, 2, 3]}]}, style={'display': 'inline-block'})
    ]),
    
    #Live BTC
    dcc.Graph(figure=fig, id='live-update-graph'),
    dcc.Interval(
        id = 'interval-component',
        interval = 1 * 1000, #Update graph every second (in milliseconds) 
        n_intervals = 0
    )
], style={'textAlign': 'center'})


# Define callback to update graph
@app.callback(
    Output('live-update-graph', 'figure'),
    [Input('interval-component', 'n_intervals')]
)

# Run app and display result external in the notebook
app.run_server(mode='external')

Does anyone know why this is? The only explanation I can think of is that my @app.callback has errors but I got it directly from an example

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles