【问题标题】:获取错误回调错误更新 logo.children、c_name.children、description.children
【发布时间】:2022-01-19 06:06:04
【问题描述】:

我无法更新图像和其他属性,例如公司名称、公司信息。在终端中,它没有显示任何错误。但是当我在屏幕上运行代码时没有任何反应。它显示错误,因为 img 是一个空元素标签,既不能有 children 也不能使用 dangerouslySetInnerHTML 和回调错误更新 logo.children、c_name.children、description.children.But在相同的代码运行良好之前。我是 dash 新手,所以我无法解决错误。

from typing import Container, ValuesView
import dash
from dash.development.base_component import Component
import dash_core_components as dcc
import dash_html_components as html
from datetime import datetime as dt
from datetime import date
from dash.dependencies import Input, Output, State
from flask.helpers import url_for
import yfinance as yf
import pandas as pd
import plotly.graph_objs as go
import plotly.express as px

app = dash.Dash(__name__)
server = app.server
app.layout=html.Div(
    className="container",
    children=[
        html.Div(children=[
            html.H1("Welcome to stock dash app!",className="start",style={'color':'#ffffff'}),
            html.Div(children=[
                html.Div([
                    dcc.Input(id="stock_code",type='text',placeholder="Enter Stock Code",className="inputbox"),
                    html.Button('Submit',id='submit_button',className="submit_button",style={'color':'#fffbf5'})
                ]),
                html.Div(
                children=[
                # Date range picker input
                dcc.DatePickerRange(
                    id='date_range_picker',
                    min_date_allowed=date(1990,12,31),
                    initial_visible_month=date(2021,12,3),
                    end_date=dt.now(), 
                )
                ]),
                html.Div(
                className='button',
                children=[
                # Stock price button
                html.Button('Stock Price',id='Stock_price_button',className="stock_p_b",style={'color':'#fffbf5'}),
                html.Button('Forcast',id='Forcast_button',className="forecast_b",style={'color':'#fffbf5'}),
                
                ]
                ),
                html.Div(children=[
                    dcc.Input(id="days",type='number',placeholder="Number of Days",className="inputbox"),
                    html.Button('Indicator',id='Indicator_button',className="indicator_b",style={'color':'#fffbf5'})
                ]
                )
            ])
            ],
                 className='nav'),
        html.Div(
        [
            html.Div(
                children=[ 
                html.Img('',id='logo',className='company_logo'),
                html.H1('',id='c_name',className='company_name',style={'color':'#064635'})
                ],
                className="header"),
            html.Div( #Description
                     html.P('',id='description', className='c_desc',style={'color':'#064635'}),),
            html.Div(
                id='stock_graph'
                ),
            html.Div(
                id='indicator_graph'),
            html.Div(
                id='forcast_graph'
                )
            ],
        className="content"
    )
    ]
)
@app.callback(
    [
        Output(component_id="logo",component_property='children'),
        Output(component_id="c_name",component_property='children'),
        Output(component_id="description",component_property='children'),
    ],
    Input(component_id='stock_code',component_property='value'),
    State(component_id='submit_button',component_property='n_clicks')
)
def update_data(arg1, arg2):
    ticker = yf.Ticker(arg1)
    inf = ticker.info
    df = pd.DataFrame().from_dict(inf, orient="index").T
    return df['logo_url'],df['shortName'],df['longBusinessSummary']


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

【问题讨论】:

    标签: python plotly plotly-dash plotly-python yfinance


    【解决方案1】:

    正如错误提示,html.Img 不应该有孩子。将其作为 src 属性传递,它应该可以工作。

    【讨论】:

    • 仍然显示回调错误。
    • 同样的错误?
    猜你喜欢
    • 1970-01-01
    • 2021-10-02
    • 2019-11-13
    • 2021-03-26
    • 2020-07-19
    • 2020-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    相关资源
    最近更新 更多