简体   繁体   English

TypeError: update_graph_scatter() 采用 0 位置 arguments 但给出了 1

[英]TypeError: update_graph_scatter() takes 0 positional arguments but 1 was given

TypeError: update_graph_scatter() takes 0 positional arguments but 1 was given TypeError: update_graph_scatter() 采用 0 位置 arguments 但给出了 1 在此处输入图像描述 Getting the above error while using dash with python.将破折号与 python 一起使用时出现上述错误。 Below is my code.下面是我的代码。

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

app = dash.Dash()

app.layout = html.Div([
    html.Div([
        html.Iframe(src = 'https://www.flightradar24.com', height = 500, width = 1200)
    ]),

    html.Div([
    html.Pre(
        id='counter_text',
        children='Active flights worldwide:'
    ),
    dcc.Graph(id='live-update-graph',style={'width':1200}),
    dcc.Interval(
        id='interval-component',
        interval=6000, # 6000 milliseconds = 6 seconds
        n_intervals=0
    )])
])
counter_list = []

@app.callback(Output('counter_text', 'children'),
              [Input('interval-component', 'n_intervals')])
@staticmethod
def update_layout(n):
    url = "https://data-live.flightradar24.com/zones/fcgi/feed.js?faa=1\
           &mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&stats=1"
    # A fake header is necessary to access the site:
    res = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
    data = res.json()
    counter = 0
    for element in data["stats"]["total"]:
        counter += data["stats"]["total"][element]
    counter_list.append(counter)
    return 'Active flights worldwide: {}'.format(counter)

@app.callback(Output('live-update-graph','figure'),
              [Input('interval-component', 'n_intervals')])
def update_graph(n):
    fig = go.Figure(
        data = [go.Scatter(
        x = list(range(len(counter_list))),
        y = counter_list,
        mode='lines+markers'
        )])
    return fig

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

As you can see in the browser i am getting this issue.正如您在浏览器中看到的那样,我遇到了这个问题。



Please help as i have tried every solution to no avail请帮助,因为我尝试了所有解决方案都无济于事

The problem is the decorator, @staticmethod , here:问题是这里的装饰器@staticmethod

@app.callback(Output('counter_text', 'children'),
              [Input('interval-component', 'n_intervals')])
@staticmethod
def update_layout(n):
    url = "https://data-live.flightradar24.com/zones/fcgi/feed.js?faa=1\
           &mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&stats=1"

This is a normal function, not a method of a class, so the @staticmethod decorator is incorrect here.这是一个普通的 function,而不是 class 的方法,所以这里的@staticmethod装饰器不正确。 I removed that, and your app worked nicely.我删除了它,您的应用程序运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:取 0 位置 arguments 但给出 1 - TypeError: takes 0 positional arguments but 1 was given Python 数据集更新 - TypeError: update() 最多需要 2 个位置参数(给出 3 个) - Python dataset update - TypeError: update() takes at most 2 positional arguments (3 given) TypeError:update()接受1到2个位置参数,但给出了3个。 - TypeError : update() takes from 1 to 2 positional arguments but 3 were given. 类型错误:update() 需要 2 个位置参数,但给出了 3 个:Python - TypeError: update() takes 2 positional arguments but 3 were given : Python TypeError: on_voice_state_update() 需要 2 个位置 arguments 但给出了 3 个 - TypeError: on_voice_state_update() takes 2 positional arguments but 3 were given Pytorch TypeError: scatter_add() 从 2 到 5 位置 arguments 但给出了 6 - Pytorch TypeError: scatter_add() takes from 2 to 5 positional arguments but 6 were given TypeError:__ init __()采用0位置参数,但给出了1 - TypeError: __init__() takes 0 positional arguments but 1 was given TypeError:publish()接受2个位置参数,但给出了3个 - TypeError: publish() takes 2 positional arguments but 3 were given TypeError:get()接受2个位置参数,但给出了3个 - TypeError: get() takes 2 positional arguments but 3 were given 类型错误:hook() 需要 2 个位置参数,但给出了 3 个 - TypeError: hook() takes 2 positional arguments but 3 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM