Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新数据表Live Python/Dash_Python_Html_Dashboard_Plotly Dash_Stock - Fatal编程技术网

更新数据表Live Python/Dash

更新数据表Live Python/Dash,python,html,dashboard,plotly-dash,stock,Python,Html,Dashboard,Plotly Dash,Stock,我有以下代码: 我需要一张经常更新库存量的桌子。 脚本不起作用,页面一直在说“加载”,如何改进它? 我想用不同的数据创建一个页面 import dash import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Input, Output import dash_bootstrap_components as dbc import pandas as p

我有以下代码: 我需要一张经常更新库存量的桌子。 脚本不起作用,页面一直在说“加载”,如何改进它? 我想用不同的数据创建一个页面

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import dash_bootstrap_components as dbc
import pandas as pd
import yahoo_fin.stock_info as si
import requests

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(
    html.Div([
        html.H4('Volume Feed'),
        html.Div(id='live-update-text'),
        #dcc.Graph(id='live-update-graph'),
        dcc.Interval(
            id='interval-component',
            interval=1*100, # in milliseconds
            n_intervals=3
        )
    ])
)


@app.callback(Output('live-update-text', 'children'),
              Input('interval-component', 'n_intervals'))
def update_metrics(n):
    QuoteTable = si.get_quote_table("aapl")
    Volume=QuoteTable["Volume"]
    row1 = html.Tr([html.Td("Previous Close",style={'font-weight':'bold'}), html.Td(Volume)])
    table_body = [html.Tbody([row1])]

    style = {'padding': '5px', 'fontSize': '16px'}
    return [
        dbc.Table(table_body,bordered=True,hover=True,responsive=True,striped=True,)
    ]



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

有什么建议吗?

您的间隔是100毫秒,在每个间隔页面上重新加载,这样您就没有机会看到任何东西。您可以更改为2000ms或更高,它可能会做到这一点。但是,如果站点有更多组件,则可能会遇到问题


interval=2*1000

您可以尝试将代码分成多个部分,然后运行每个部分,以查看瓶颈在哪里