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

问题描述

我已经为耐克运动鞋收集了大量销售数据,并使用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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...