【问题标题】:Dash Callback error: unhashable type: 'Figure'Dash 回调错误:不可散列的类型:'Figure'
【发布时间】:2020-08-04 13:24:09
【问题描述】:

我想用破折号更新饼图:

@app.callback(
    Output('piechart','figure'),
    [Input('piechartinput', 'value')]
)
def update_piechart(new_val):
    return {px.pie(dfs, names = new_val, values='Wert')}

很遗憾,我收到了这个错误:

Traceback (most recent call last):
  File "C:\Users\TO3THY0\.spyder-py3\Dashboard\Dashboard.py", line 153, in update_piechart
    return {px.pie(dfs, names = new_val, values='Wert')}
TypeError: unhashable type: 'Figure'

有人可以帮我吗?谢谢!

【问题讨论】:

    标签: python dashboard plotly-dash


    【解决方案1】:

    在您的回调中,您返回 piechart.figure 的新值。如https://plotly.com/python/creating-and-updating-figures/ 中所述,您可以传递包含一个data 和一个layout 字段的字典。在您的代码中,您使用了错误的语法,导致该图被用作键而不是值。由于该数字不可散列,因此您会收到错误消息。使用 plotly express 可以直接传图。

    在您的示例中,正确的实现可能如下所示:

    @app.callback(
        Output('piechart','figure'),
        [Input('piechartinput', 'value')]
    )
    def update_piechart(new_val):
        return px.pie(dfs, names=new_val, values='Wert')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 2017-03-11
      • 1970-01-01
      • 2017-12-27
      • 2019-01-07
      • 2018-01-10
      相关资源
      最近更新 更多