如何解决TypeError.Dash_html_components.Div`组件(版本1.0.3)的TypeError问题。`dash_html_components.Div`组件(版本1.0.3)与plotly-dash一起使用。

问题描述 投票:0回答:1

我试图在我的绘图中添加文本,使我的文本与绘图的结果容易理解。当我尝试构建第一个标签时,我得到以下错误。

**TypeError** : The dash_html_components.Divcomponent (version 1.0.3) with the ID "Div(children=(Br(None), P('Select a year and month to query'), Br(None)), id='paragraph1')" detected a Component for a prop other thanchildrenDid you forget to wrap multiplechildren in an array? Prop n_clicks has value Div(children=[Dropdown(id='month', options=[{'label': 'January', 'value': 1}, {'label': 'February', 'value': 2}, {'label': 'March', 'value': 3}, {'label': 'April', 'value': 4}, {'label': 'May', 'value': 5}, {'label': 'June', 'value': 6}, {'label': 'July', 'value': 7}, {'label': 'August', 'value': 8}, {'label': 'September', 'value': 9}, {'label': 'October', 'value': 10}, {'label': 'November', 'value': 11}, {'label': 'December', 'value': 12}], value=3, style={'width': '50%'})], style={'width': '100%', 'display': 'flex', 'flex-direction': 'row'})

这里是有问题的代码部分。

def tab_layout():

     return html.Div(

            html.Div(

                        id="markdown-container",

                        children=dcc.Markdown(

                            children=(

                                """

                                    my text text

                                    ### Funnel Area Chat

                                    more text more text more text

                    """

                            ), 

                            style={"color": "white"}

                        ),

                    ),



            html.Div(

                id="paragraph1",

                children= (

                    html.Br(),

                    html.P("Select a year and month to query"),

                    html.Br()



                )



            ),



             html.Div([

                dcc.Dropdown(

                    id="month",

                    options= month_options(),

                    value=3,

                    style={"width": "50%"}

                    ),

                    ], style={"width": "100%", "display": "flex", "flex-direction": "row"}),

                 dcc.Dropdown(

                     id="year",

                     options=[

                         {"label": "2019", "value": 2019},

                         {"label": "2020", "value": 2020}

                     ],

                     value=2020,

                     style={"width": "50%", "display": "flex", "flex-direction": "row", 

                            "justify-content": "left"}

                     ),

            html.Div([

                dcc.Graph(id="funnel_plot",

                          config= {

                              "displaylogo": False,

                              "toImageButtonOptions": {"width": None, "height": None}

                          }



                        )

                ], style={"width": "100%", "display": "inline-block"})

                )

什么地方出了问题?编译器没有看到任何错误?我写想弄清楚这一点没有得到它。

谢谢您的帮助

python python-3.x plotly plotly-dash plotly-python
1个回答
2
投票

当你把多个元素包含在 children 属于 html.Div() 您需要确保它们被置于方括号内,因为 children 属于 html.Div() 是一个列表(见 仪表盘文件). 我根据你的代码在下面加入了一个例子。

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go

app = dash.Dash()

app.layout = html.Div(children=[

    html.Div(children=[

        html.Div(

            id="markdown-container",

            children=dcc.Markdown(

                children="""

                        my text text

                        ### Funnel Area Chat

                        more text more text more text

                    """,

                style={"color": "white"}

            ),

        ),

        html.Div(

            id="paragraph1",

            children=[

                html.Br(),

                html.P("Select a year and month to query"),

                html.Br()

            ]

        ),

        html.Div(children=[

            dcc.Dropdown(

                id="month",

                value=3,

                style={"width": "50%"}

            ),

        ], style={"width": "100%", "display": "flex", "flex-direction": "row"}),

        dcc.Dropdown(

            id="year",

            options=[

                {"label": "2019", "value": 2019},

                {"label": "2020", "value": 2020}

            ],

            value=2020,

            style={"width": "50%", "display": "flex", "flex-direction": "row",

                   "justify-content": "left"}

        ),

        html.Div(children=[

            dcc.Graph(id="funnel_plot",

                      config={

                          "displaylogo": False,

                          "toImageButtonOptions": {"width": None, "height": None}

                      }

            ),

        ], style={"width": "100%", "display": "inline-block"}),

    ])

])

app.run_server(debug=False)
© www.soinside.com 2019 - 2024. All rights reserved.