微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何修复我的应用程序回调以获取下拉列表和散点图?

如何解决如何修复我的应用程序回调以获取下拉列表和散点图?

我已经为耐克运动鞋收集了大量销售数据,并使用Python和Dash创建了一个仪表板。我的仪表板运行良好,但无法确定如何添加有效的下拉过滤器。我已经在仪表板上显示了过滤器,但是它没有执行任何操作,并引发了重复回调输出的应用内错误。我认为我的app.callback中有问题。我正在使用四个不同的数据帧:“ product_df”,“ red”,“ roy”和“ obs”。由于在Python和Dash方面还比较陌生,因此我在Excel中分离出了不同的颜色方式。我还在单独的单元格中开发了Plotly图。

这是我的仪表板的代码

colors = {
    'background': '#FFFFFF','text': '#000000'
}

app.layout = html.Div(style={'backgroundColor': colors['background']},children=[
    html.Div([
        html.H1( # Title
            children='Nike Air Max 1 - Anniversary Resale Dashboard',style={
                'textAlign': 'center','color': colors['text']
            }
        )
    ],className = 'row'),# Description
    html.Div(
        children="The Nike Air Max 1 was released in 1987,designed by Tinker Hatfield. Mr. Hatfield based the concept off of the Centre Pompidou in Paris,France. I believe the Air Max 1 embodies Nike's history of innovation and success. In 2017,for the 30 year anniversary of the model,Nike reproduced three of the original colorways: Obsidian,Royal (blue),and Red. I gathered resale data from StockX on these three colorways. I used Postman API to extract data from the service. The extraction resulted in a json file that was then converted into an Excel file. This Python dashboard will explore trends in the resale market that Nike can use to understand time-based consumer demand. This dashboard unveils a few things about the Air Max 1 Anniversary resale market. The sales volume graph shows that since 2017,the Obsidian color-way was resold the most. This would normally indicate the Obsidian is the most popular,but in the resale market high volume normally means most easily accessible. The Box plot shows this to be true as the Obsidian’s have the lowest median resale price at $198. However,based on the scatterplot and line graph,the color has been constantly increasing in value. The most sales for these colors occurred from march to November 2017. The Red and Royal then saw a dip in prices during the third quarter of 2018. The highest median resale value comes from the Royal’s at $320,and has the highest resale price at $623. Overall,the Nike Air Max 1 has maintained its popularity and value to the sneaker industry and Nike overall.",style={
            'textAlign': 'center','color': colors['text']
        }
    ),# Filter
    dcc.Dropdown(
        id='dropdown',options=[
            {'label': 'Red','value': 'red'},{'label': 'Royal','value': 'royal'},{'label': 'Obsidian','value': 'obsidian'}
        ],value=['red','royal','obsidian'],multi=True
    ),# Graphs
    dcc.Graph(id ='pricedate',figure=fig3),html.Div([
        html.Div([
            dcc.Graph(id = 'salesvolume',figure=fig1)
        ],className='six columns'),html.Div([
            dcc.Graph(id = 'Boxandwhiskers',figure=fig2)
        ],],className='row')
    

])

@app.callback(
    dash.dependencies.Output('pricedate','figure'),[dash.dependencies.Input('dropdown','update_graph')]
)

def update_graph(selector):
    data = []
    if 'red' in selector:
        data.append({'x': red['date'],'y': red['price'],'type':'scatter','name':'red'})
    if 'royal' in selector:
        data.append({'x': roy['date'],'y': roy['price'],'name':'royal'})
    if 'obsidian' in selector:
        data.append({'x': obs['date'],'y': obs['price'],'name':'obsidian'})
        
    figure = {
        'data': data,'layout': {
            'title' = 'Air Max 1 Resale Price vs. Date','xaxis' = 'Month','yaxis' = 'Price ($)'   
        }   
    }
    return figure

app.run_server(debug=True,use_reloader=False)

我还不断收到有关我的update_graph图形标题语法的错误。感谢您提供有关如何纠正错误的反馈。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。