小编Sco*_*son的帖子

返回数字字典时回调返回值无效

我试图返回一个条形图,但用于条形图的列根据下拉值选择而变化。我将字典返回到 graph.figure 输出,但收到以下错误;

dash.exceptions.InvalidCallbackReturnValue:
The callback for property \figure``
of component \graph-one` returned a value`    
which is not JSON serializable.        

In general, Dash properties can only be    
dash components, strings, dictionaries, numbers, None,    
or lists of those.
Run Code Online (Sandbox Code Playgroud)

我的返回值是一本字典。代码如下;

def create_grouped_bar(df):
    return [    
        go.Bar(
            x=df['date'],    
            y=df[col],    
            text=df[col],    
            hoverinfo='text+name',    
            name=col.title(),    
            )
        for col in df.columns
        ]    

@app.callback(    
        Output('graph-one', 'figure'),   
        [Input('filtered_df', 'children'),    
        Input('freq-radio', 'value'),    
        Input('graph-one-drop', 'value'),    
        Input('graph-one-radio', 'value')])    
def update_graph(df_json, freq, cols, amount):    
    dff = pd.read_json(df_json, orient='split')    
    plot_cols = falls_dd_dict[cols]

    plot_df = dff[['date_time_occurred']+plot_cols].copy() …
Run Code Online (Sandbox Code Playgroud)

python plotly plotly-dash

5
推荐指数
1
解决办法
6781
查看次数

标签 统计

plotly ×1

plotly-dash ×1

python ×1