【问题标题】:Error: object was provided as `children` instead of a component, string, or number (or list of those)错误:对象作为“子项”提供,而不是组件、字符串或数字(或这些对象的列表)
【发布时间】:2020-10-28 21:55:33
【问题描述】:

我似乎无法找出为什么会在开发者控制台中弹出此错误。该脚本在 R 中完美运行,并且之前运行过。我记得从脚本中删除了一个回调,但就是这样。下面是包含应用程序布局 html 部分的 R 脚本。有人可以帮忙吗?

app$layout(
  htmlDiv(
    children = list(
      htmlDiv(
        list(
          htmlDiv(
            list(
              htmlH3(
                "Maternal Health Dashboard",
                style=list("margin-bottom"= "0px",
                           "text-align" = "center")
              )
            )
          )
        ),
        className="row flex-display",
        id="title",
        style=list("margin-bottom"= "25px")
      ),
      htmlDiv(
        list(
          htmlP("Tabs", className="tabs"),
          dccRadioItems(
            id="tab_buttons",
            options = list(
              list("label"= "General", "value"= "general"),
              list("label"= "Antenatal", "value"= "antenatal_risk"),
              list("label"= "Postnatal ", "value"= "postnatal_details"),
              list("label"= "LBW Child ", "value"= "LBW_details")
            ),
            value="general",
            labelStyle=list("display"= "inline-block","text-align" = "center"
            ),
            className="dcc_control"
          )
        )
      ),
      htmlDiv(
        id = "map-container",
        list(
          htmlP("Map of Maternal Health",
                id = "map-title",
          ),
          dccGraph(figure=fig
          )
        )
      ),
      htmlDiv(
        list(
          htmlP("Total GP "),
          htmlP("Total Sub Centers  "),
          htmlP("Total Villages "),
          htmlP("Total Beneficiary Women  "),
          htmlP("Total Postnatal Women  "),
          htmlP("Total Neonatal Women   ")
        ),
        style= list("display"= "flex","border"= "2px solid powderblue","white-space" = "normal", "justify-content" = "space-around"),
        id="info-container",
        className="row container-display"
      ),
      htmlDiv(
        id = "graph-container",
        list(
          htmlP(id="chart-selector",
                children = "Select chart:"
          ),
          dccDropdown(
            options = list(list("label"= "Total number of infants per Woman ",
                                "value"= "show_absolute_deaths_single_year"),
                           list("label"= "COVID-19 Cases",
                                "value"= "absolute_deaths_all_time"),
                           list("label"= "Total number of post-natal immunizations",
                                "value"= "show_death_rate_single_year"),
                           list("label"= "",
                                "value"= "death_rate_all_time")),
            value="show_death_rate_single_year",
            id="chart-dropdown"
          ),
          dccGraph(
            id = "selected-data"
          )
        )
      ),
      id="mainContainer",
      style = list(
        "position" = "relative",
        "box-sizing" =  "border-box"
      )
    )))


app$run_server()

【问题讨论】:

    标签: html r plotly plotly-dash plotly-dashr


    【解决方案1】:

    我用 Python 而不是 R 编写 Dash,但我怀疑这些行为非常相似,以至于您的问题来自这两个地方:

          htmlDiv(
            id = "map-container",
            list(
              htmlP("Map of Maternal Health",
                    id = "map-title",
              ),
              dccGraph(figure=fig
              )
            )
          ),
    
          htmlDiv(
            id = "graph-container",
            list(
              htmlP(id="chart-selector",
                    children = "Select chart:"
              ),
              dccDropdown(
                options = list(list("label"= "Total number of infants per Woman ",
                                    "value"= "show_absolute_deaths_single_year"),
                               list("label"= "COVID-19 Cases",
                                    "value"= "absolute_deaths_all_time"),
                               list("label"= "Total number of post-natal immunizations",
                                    "value"= "show_death_rate_single_year"),
                               list("label"= "",
                                    "value"= "death_rate_all_time")),
                value="show_death_rate_single_year",
                id="chart-dropdown"
              ),
              dccGraph(
                id = "selected-data"
              )
            )
          ),
    

    默认情况下,Dash 组件期望 children 属性是第一个传入的东西。在这些情况下,您首先提供了 id,但没有显式设置 children=,所以它没有不知道如何处理该组件。要么明确地将它们设为children,要么将它们设为组件的第一件事。

    【讨论】:

      猜你喜欢
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-11
      相关资源
      最近更新 更多