首页 > 解决方案 > Plotly/dash - 模块“dash_html_components”没有“Div”成员

问题描述

我想从 plotly 运行这段代码。
之前,我安装了这些模块:

pip install dash==0.21.1  # The core dash backend
pip install dash-renderer==0.13.0  # The dash front-end
pip install dash-html-components==0.11.0  # HTML components
pip install dash-core-components==0.23.0  # Supercharged components
pip install plotly --upgrade  # Latest Plotly graphing library

我的代码是:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'}, 
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

但是它不起作用,我不明白为什么!你能帮我吗 !谢谢

标签: pythonplotly-dash

解决方案


我知道这是一个老问题,但我最近遇到了这个错误,之前的答案没有帮助。

经过进一步探索,此错误的原因是软件包dash_html_components已被弃用。

解决方案: 替换 import dash_core_components as dcc from dash import dcc

此外,现在已弃用的其他类似软件包是dash_html_components


推荐阅读