0
  • I am trying to plot live graphs onto a website using dash with python
  • Using the latest version of Dash
  • got to know the event was removed from the latest version

so now how do I approach this problem any help will be appreciated.

Traceback (most recent call last): File "C:/Users/rohit/PycharmProjects/flask-projects/pltexmple.py", line 28, in events=[Event('graph-update', 'interval')]) NameError: name 'Event' is not defined

import dash
from dash.dependencies import Output
import dash_core_components as dcc
import dash_html_components as html
import plotly
import random
import plotly.graph_objs as go
from collections import deque

X = deque(maxlen=20)
X.append(1)
Y = deque(maxlen=20)
Y.append(1)


app = dash.Dash(__name__)
app.layout = html.Div(
    [
        dcc.Graph(id='live-graph', animate=True),
        dcc.Interval(
            id='graph-update',
            interval=1*1000
        ),
    ]
)

@app.callback(Output('live-graph', 'figure'),
              [Input('graph-update', 'interval')])
def update_graph_scatter():
    X.append(X[-1]+1)
    Y.append(Y[-1]+Y[-1]*random.uniform(-0.1,0.1))

    data = plotly.graph_objs.Scatter(
            x=list(X),
            y=list(Y),
            name='Scatter',
            mode= 'lines+markers'
            )

    return {'data': [data],'layout' : go.Layout(xaxis=dict(range=[min(X),max(X)]),
                                                yaxis=dict(range=[min(Y),max(Y)]),)}



if __name__ == '__main__':
    app.run_server(debug=True)
6
  • 1
    Hi, does this answer your question? stackoverflow.com/questions/54807868/… Commented Jul 2, 2021 at 6:16
  • hi, i tried to do it before but it gives me TypeError: update_graph_scatter() takes 0 positional arguments but 1 was given Commented Jul 2, 2021 at 6:20
  • I have updated the callback, can you confirm that is how i should do Commented Jul 2, 2021 at 6:23
  • 1
    The code line from the traceback does not appear in your code. Check if you posted the right code and add the full traceback to the question! Commented Jul 2, 2021 at 6:26
  • 1
    The edit looks good. One more thing, accept an argument in your function. def update_graph_scatter(input_value): and change interval to n_intervals Commented Jul 2, 2021 at 6:37

1 Answer 1

1

The event was removed in the latest version of the Dash, thats why you are getting an error.

Please change the code to the below one.

import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly
import random
import plotly.graph_objs as go
from collections import deque

X = deque(maxlen=20)
X.append(1)
Y = deque(maxlen=20)
Y.append(1)


app = dash.Dash(__name__)
app.layout = html.Div(
    [
        dcc.Graph(id='live-graph', animate=True),
        dcc.Interval(
            id='graph-update',
            interval=1*1000
        ),
    ]
)

@app.callback(Output('live-graph', 'figure'),
              [Input('graph-update', 'n_intervals')])
def update_graph_scatter(input_data):
    X.append(X[-1]+1)
    Y.append(Y[-1]+Y[-1]*random.uniform(-0.1,0.1))

    data = plotly.graph_objs.Scatter(
            x=list(X),
            y=list(Y),
            name='Scatter',
            mode= 'lines+markers'
            )

    return {'data': [data],'layout' : go.Layout(xaxis=dict(range=[min(X),max(X)]),
                                                yaxis=dict(range=[min(Y),max(Y)]),)}


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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.