我试图返回一个条形图,但用于条形图的列根据下拉值选择而变化。我将字典返回到 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)