Plotly Dash 回调 | SchemaLengthValidationError - 预期 7,收到 8 或 Dash 回调的“输出”中使用了不存在的对象

2024-04-18

目标:再追加 1 个Output list.

Updates在帖子底部。


我想要output marker_symbol, 从每个trace dict, (as line_marker) to a Plot在本地主机前端。发生错误是因为我还没有Output() for it.

我确实有一个Input and State for it:

  • Input(self.customisation_tab.line_marker_button.id, 'n_clicks'),
  • State(self.customisation_tab.line_marker.id, 'value').

Note: customisation_tab是的一部分Dash网页。

这个功能,line_marker, 是复写本line_colour.

  • 下拉列表,包含可供选择的符号,
  • 应用更改的按钮。

我怎样才能写一个Output()为了这?


输入、状态、输出代码:

@property
def callbacks(self) -> list:
    callbacks = super().callbacks
    callbacks.extend([
        ... # irrelevant methods redacted
        (self.render_graph,
         [Output(self.graph.id, 'figure'),  # Error
          Output(self.colour_string_div.id, 'children'),
          Output(self.data_persisted_flag.id, 'children'),
          Output(self.variables_tab.xaxis_datepicker.id, 'start_date'),
          Output(self.variables_tab.xaxis_datepicker.id, 'end_date'),
          Output(self.variables_tab.yaxis_warning.id, 'children'),
          Output(self.variables_tab.filtered_data_args_div.id, 'children')],  # Error
         [Input(self.initialised_cache_flag.id, 'children'),
          Input(self.location.id, 'href'),
          Input(self.instance_id_div.id, 'children'),
          Input(self.apply_button.id, 'n_clicks'),
          Input(self.next_button.id, 'n_clicks'),
          Input(self.customisation_tab.line_mode.id, 'value'),
          Input(self.customisation_tab.line_width.id, 'value'),
          Input(self.customisation_tab.line_opacity.id, 'value'),
          Input(self.customisation_tab.line_marker_button.id, 'n_clicks'),
          Input(self.customisation_tab.line_colour_button.id, 'n_clicks'),
          Input(self.customisation_tab.error_colour_radioitems.id, 'value'),
          Input(self.customisation_tab.error_colour_dropdown.id, 'value'),
          Input(self.customisation_tab.error_width.id, 'value'),
          Input(self.customisation_tab.title.id, 'value'),
          Input(self.customisation_tab.xaxis_label.id, 'value'),
          Input(self.customisation_tab.line_style.id, 'value'),
          Input(self.customisation_tab.yaxis_label.id, 'value'),
          Input(self.customisation_tab.yaxis2_label.id, 'value'),
          Input(self.customisation_tab.gridlines_checklist.id, 'value'),
          Input(self.customisation_tab.axes_checklist.id, 'value'),
          Input(self.customisation_tab.origin_checklist.id, 'value')],
         [State(self.graph.id, 'figure'),
          State(get_pattern_matching_id(self.filter_tab.filter_panel.methods_radio.id, ALL), 'value'),
          State(get_pattern_matching_id(self.filter_tab.filter_panel.features_dropdown.id, ALL),
                'value'),
          State(get_pattern_matching_id(self.filter_tab.filter_panel.feature_values_dropdown.id, ALL),
                'value'),
          State(get_pattern_matching_id(self.filter_tab.filter_panel.slider.id, ALL), 'value'),
          State(get_pattern_matching_id(self.filter_tab.filter_panel.date_picker.id, ALL), 'start_date'),
          State(get_pattern_matching_id(self.filter_tab.filter_panel.date_picker.id, ALL), 'end_date'),
          State(self.variables_tab.xaxis_dropdown.id, 'value'),
          State(self.variables_tab.counter_checklist.id, 'value'),
          State(self.variables_tab.xaxis_min_input.id, 'value'),
          State(self.variables_tab.xaxis_max_input.id, 'value'),
          State(self.variables_tab.xaxis_datepicker.id, 'start_date'),
          State(self.variables_tab.xaxis_datepicker.id, 'end_date'),
          State(self.variables_tab.yaxis_min_input.id, 'value'),
          State(self.variables_tab.yaxis_max_input.id, 'value'),
          State(self.variables_tab.yaxis2_min_input.id, 'value'),
          State(self.variables_tab.yaxis2_max_input.id, 'value'),
          State(self.variables_tab.yaxis_dropdown.id, 'value'),
          State(self.variables_tab.yaxis2_checklist.id, 'value'),
          State(self.variables_tab.yaxis2_dropdown.id, 'value'),
          State(self.variables_tab.category_checklist.id, 'value'),
          State(self.variables_tab.category_dropdown.id, 'value'),
          State(self.variables_tab.quantile_slider.id, 'value'),
          State(self.variables_tab.groupby_radio.id, 'value'),
          State(self.variables_tab.coerce_checklist.id, 'value'),
          State(self.customisation_tab.line_marker.id, 'value'),
          State(self.customisation_tab.line_colour.id, 'value'),
          State(self.additional_variables_tab.log_transform_checklist.id, 'value'),
          State(self.additional_variables_tab.log_transform_radioitems.id, 'value'),
          State(self.additional_variables_tab.plot_mean.id, 'value'),
          State(self.additional_variables_tab.plot_error.id, 'value'),
          State(self.additional_variables_tab.error_type.id, 'value'),
          State(self.additional_variables_tab.standard_error.id, 'value')])
    ])
    return callbacks

追溯:

Traceback (most recent call last):
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/dash/dash.py", line 1383, in dispatch
    response.set_data(func(*args, outputs_list=outputs_list))
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/dash/_callback.py", line 166, in add_context
    flat_output_values = flatten_grouping(output_value, output)
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/dash/_grouping.py", line 34, in flatten_grouping
    validate_grouping(grouping, schema)
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/dash/_grouping.py", line 214, in validate_grouping
    SchemaLengthValidationError.check(grouping, full_schema, path, len(schema))
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/dash/_grouping.py", line 183, in check
    raise SchemaLengthValidationError(value, full_schema, path, expected_len)
dash._grouping.SchemaLengthValidationError: Schema: [<Output `graph-with-dropdown.figure`>, <Output `colour-string-div.children`>, <Output `data-persisted-div.children`>, <Output `xaxis-datepicker.start_date`>, <Output `xaxis-datepicker.end_date`>, <Output `yaxis-warning.children`>, <Output `variables-tab-filter-change-div.children`>]
                Path: ()
                Expected length: 7
                Received value of length 8:
                    [Figure({
    'data': [{'error_y': {'color': '#2dd070', 'symmetric': True, 'thickness': 2, 'type': 'data', 'width': 2},
              'line': {'color': '#2dd070', 'dash': 'solid', 'width': 2},
              'marker': {'size': 6, 'symbol': ['circle', 'square-dot']},
              'mode': 'lines+markers',
              'name': '_percent_Tumour',
              'opacity': 0.8,
              'type': 'scatter',
              'x': [2020-06-01 00:00:00, 2020-06-02 00:00:00, 2020-06-03 00:00:00,
                    2020-06-04 00:00:00, 2020-06-05 00:00:00, 2020-06-06 00:00:00,
                    2020-06-07 00:00:00, 2020-06-08 00:00:00, 2020-06-09 00:00:00,
                    2020-06-10 00:00:00, 2020-06-11 00:00:00, 2020-06-12 00:00:00,
                    2020-06-13 00:00:00, 2020-06-14 00:00:00, 2020-06-15 00:00:00,
                    2020-06-16 00:00:00, 2020-06-17 00:00:00, 2020-06-18 00:00:00,
                    2020-06-19 00:00:00, 2020-06-20 00:00:00, 2020-06-21 00:00:00,
                    2020-06-22 00:00:00, 2020-06-23 00:00:00, 2020-06-24 00:00:00,
                    2020-06-25 00:00:00, 2020-06-26 00:00:00, 2020-06-27 00:00:00,
                    2020-06-28 00:00:00, 2020-06-29 00:00:00, 2020-06-30 00:00:00,
                    2020-07-01 00:00:00, 2020-07-02 00:00:00, 2020-07-03 00:00:00,
                    2020-07-04 00:00:00, 2020-07-05 00:00:00, 2020-07-06 00:00:00,
                    2020-07-07 00:00:00, 2020-07-08 00:00:00, 2020-07-09 00:00:00,
                    2020-07-10 00:00:00, 2020-07-11 00:00:00, 2020-07-12 00:00:00,
                    2020-07-13 00:00:00, 2020-07-14 00:00:00, 2020-07-15 00:00:00,
                    2020-07-16 00:00:00, 2020-07-17 00:00:00, 2020-07-18 00:00:00,
                    2020-07-19 00:00:00, 2020-07-20 00:00:00, 2020-07-21 00:00:00,
                    2020-07-22 00:00:00, 2020-07-23 00:00:00, 2020-07-24 00:00:00,
                    2020-07-25 00:00:00, 2020-07-26 00:00:00, 2020-07-27 00:00:00,
                    2020-07-28 00:00:00, 2020-07-29 00:00:00, 2020-07-30 00:00:00],
              'y': [32.69230769230769, 38.333333333333336, 49.23076923076923,
                    53.1578947368421, 47.0, 43.0, 47.35294117647059,
                    61.904761904761905, 44.23076923076923, 57.69230769230769, 52.5,
                    42.5, 45.0, 50.0, 40.294117647058826, 32.857142857142854, 50.0,
                    54.11764705882353, 50.0, 52.5, 38.75, 39.0, 34.54545454545455,
                    39.0, 30.0, 32.5, 42.666666666666664, 45.0, 49.333333333333336,
                    39.285714285714285, 43.1578947368421, 50.65217391304348,
                    36.666666666666664, 66.25, 39.35897435897436,
                    42.333333333333336, 30.0, 63.1578947368421, 37.64705882352941,
                    46.666666666666664, 41.42857142857143, 43.84615384615385,
                    45.16129032258065, 46.0, 44.285714285714285,
                    30.526315789473685, 46.1764705882353, 40.0, 43.125, 45.0,
                    43.57142857142857, 43.5, 56.666666666666664, 34.09090909090909,
                    46.25, 33.57142857142857, 47.5, 49.166666666666664,
                    49.333333333333336, 34.44444444444444],
              'yaxis': 'y'},
             {'error_y': {'color': '#d62728', 'symmetric': True, 'thickness': 2, 'type': 'data', 'width': 2},
              'line': {'color': '#d62728', 'dash': 'solid', 'width': 2},
              'marker': {'size': 6, 'symbol': ['circle', 'square-dot']},
              'mode': 'lines+markers',
              'name': 'Age',
              'opacity': 0.8,
              'type': 'scatter',
              'x': [2020-06-01 00:00:00, 2020-06-02 00:00:00, 2020-06-03 00:00:00,
                    2020-06-04 00:00:00, 2020-06-05 00:00:00, 2020-06-06 00:00:00,
                    2020-06-07 00:00:00, 2020-06-08 00:00:00, 2020-06-09 00:00:00,
                    2020-06-10 00:00:00, 2020-06-11 00:00:00, 2020-06-12 00:00:00,
                    2020-06-13 00:00:00, 2020-06-14 00:00:00, 2020-06-15 00:00:00,
                    2020-06-16 00:00:00, 2020-06-17 00:00:00, 2020-06-18 00:00:00,
                    2020-06-19 00:00:00, 2020-06-20 00:00:00, 2020-06-21 00:00:00,
                    2020-06-22 00:00:00, 2020-06-23 00:00:00, 2020-06-24 00:00:00,
                    2020-06-25 00:00:00, 2020-06-26 00:00:00, 2020-06-27 00:00:00,
                    2020-06-28 00:00:00, 2020-06-29 00:00:00, 2020-06-30 00:00:00,
                    2020-07-01 00:00:00, 2020-07-02 00:00:00, 2020-07-03 00:00:00,
                    2020-07-04 00:00:00, 2020-07-05 00:00:00, 2020-07-06 00:00:00,
                    2020-07-07 00:00:00, 2020-07-08 00:00:00, 2020-07-09 00:00:00,
                    2020-07-10 00:00:00, 2020-07-11 00:00:00, 2020-07-12 00:00:00,
                    2020-07-13 00:00:00, 2020-07-14 00:00:00, 2020-07-15 00:00:00,
                    2020-07-16 00:00:00, 2020-07-17 00:00:00, 2020-07-18 00:00:00,
                    2020-07-19 00:00:00, 2020-07-20 00:00:00, 2020-07-21 00:00:00,
                    2020-07-22 00:00:00, 2020-07-23 00:00:00, 2020-07-24 00:00:00,
                    2020-07-25 00:00:00, 2020-07-26 00:00:00, 2020-07-27 00:00:00,
                    2020-07-28 00:00:00, 2020-07-29 00:00:00, 2020-07-30 00:00:00],
              'y': [75.15384615384616, 53.333333333333336, 80.6923076923077,
                    67.36842105263158, 68.8, 72.1, 64.52941176470588,
                    60.95238095238095, 63.0, 71.84615384615384, 75.125, 47.6, 56.0,
                    46.0, 48.76470588235294, 74.57142857142857, 51.0,
                    73.52941176470588, 77.5, 62.0, 77.0625, 72.5,
                    66.86363636363636, 56.0, 79.2, 80.9, 59.93333333333333,
                    55.888888888888886, 70.2, 66.14285714285714, 63.89473684210526,
                    66.0, 72.55555555555556, 74.0, 54.1025641025641,
                    66.53333333333333, 80.44444444444444, 69.89473684210526,
                    71.58823529411765, 71.66666666666667, 56.142857142857146,
                    47.46153846153846, 72.74193548387096, 78.6, 67.92857142857143,
                    56.26315789473684, 72.29411764705883, 62.81818181818182,
                    63.125, 72.0909090909091, 67.52380952380952, 76.5, 74.0,
                    55.54545454545455, 55.25, 66.28571428571429, 65.0,
                    77.41666666666667, 66.8, 65.66666666666667],
              'yaxis': 'y2'}],
    'layout': {'showlegend': False,
               'template': {},
               'transition': {'duration': 2000, 'easing': 'cubic-in-out'},
               'xaxis': {'range': [None, None],
                         'showgrid': True,
                         'showline': False,
                         'title': {'text': 'Test_DateTime'},
                         'zeroline': False},
               'yaxis': {'range': [None, None],
                         'showgrid': True,
                         'showline': False,
                         'title': {'text': '_percent_Tumour'},
                         'zeroline': False}}
}), ['circle', 'square-dot'], ['#2dd070', '#d62728'], <dash._callback.NoUpdate object at 0x7f73bf594730>, <dash._callback.NoUpdate object at 0x7f73bf594730>, <dash._callback.NoUpdate object at 0x7f73bf594730>, '', '22380905-06ff-4365-b479-a8380a994b7a']

定义marker_string_div并附加到Output():

callbacks.extend([
        ... # irrelevant methods redacted
        (self.render_graph,
         [Output(self.graph.id, 'figure'),
          Output(self.marker_string_div.id, 'children'), # Appended
          Output(self.colour_string_div.id, 'children'),
...

立即错误:

A nonexistent object was used in an `Output` of a Dash callback. The id of this object is `marker-string-div` and the property is `children`. The string ids in the current layout are: [url, page-content, app-title-header, last-modified-header, wrapped-tabs, filter-tab, filter-panel-container, initialise-data-flag-filter, variables-tab, groupby-radio, num2-bool, cat-bool, counter-checklist, xaxis-dropdown, num-dropdown, yaxis-warning, num2-style, num2-dropdown, xaxis-range-style, x-axis-min, x-axis-max, xaxis-datepicker-style, xaxis-datepicker, y-axis-min, y-axis-max, yaxis2-min- range-div, y-axis2-min, yaxis2-max- range-div, y-axis2-max, category-div, cat-dropdown, quantile-slider-style, num-to-cat-checklist, quantile-slider-div, quantile-slider, variables-tab-filter-change-div, variables-tab-load-data-args, additional-variables-tab, log-transform-checklist, log-transform-radioitems, mean-checklist, error-checklist, standard-error, standard-error-checklist, error-bars, error-radioitems, customise-tab, title-input, xaxis-input, yaxis-input, yaxis2-style, yaxis2-input, dash-checklist, mode-dropdown, gridlines-checklist, axes-checklist, origin-checklist, marker-dropdown, marker-button, colour-dropdown, colour-button, width-slider, opacity-slider, error-bar-width-slider, error-colour-radioitems, error-colour_div, error-colour-dropdown, download-tab, csv-tooltip, excel-tooltip, html-tooltip, presigned-url-csv-div, presigned-url-xlsx-div, presigned-url-html-div, download-tab-file-name-input-box, transpose-checklist, download-tab-report-title-input-box, report-notes, optional-data-div, optional-data-checklist, csv-button, excel-button, html-button, save-html-button, update-download-data-flag, reload-data-flag, html-report-div, saved-report-popup, save-report-flag, presigned-url-div, download-div, apply-button, apply-button-tooltip, next-app-style, next-app-button, graph-with-dropdown, colour-string-div, signal-div, instance-id-div, initialised-cache-flag, current-tab-id, step, data-persisted-div, hidden-div]

首先,我必须附加并返回body_div:

@property
    def body_div(self) -> Div:
        return Div([self.graph, self.marker_string_div])

因为我的选项卡都在一页上,所以大多数组件都需要显示和消失。但是,我希望图表及其标记始终出现在这种情况下。

最后(主要部分),我必须将其添加到 Dash 应用程序的Layout。我曾经写过marker_string_div组件、函数、验证和 UI 元素。我需要做的就是将其添加到返回行中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Plotly Dash 回调 | SchemaLengthValidationError - 预期 7,收到 8 或 Dash 回调的“输出”中使用了不存在的对象 的相关文章

随机推荐

  • C# .net 协议缓冲区 - protobuf-net 支持序列化对象值字典吗?

    我是协议缓冲区的新手 我正在使用 VS2010 的 protobuf net 从我在这里读到的内容协议缓冲区中的字典 https stackoverflow com questions 4194845 dictionary in proto
  • 使用 ctypes 从 python 访问 boost::进程间共享内存块

    我在 Windows 上运行的 C 程序中有一个结构 我想使用 ctypes 通过 Python 中的共享内存来访问该结构 例如 define MAX ENTITIES 30 struct State double x double y d
  • 如何用imshow()限制x轴的范围?

    我有以下数据 1 105 0 919 0 842 0 715 0 704 0 752 0 827 1 049 0 584 0 998 0 931 0 816 0 787 0 803 0 856 0 782 0 872 0 710 1 268
  • D3 树方向

    我正在使用 D3 树布局 类似于此jsfiddle https jsfiddle net vrkrympk 唯一的问题是我需要每个节点的方向从布局的左上角开始 而不是从顶部中心开始 var nodeUpdate node transitio
  • 从 Google 云存储中删除文件

    因此 我在 appengine 上启动并运行了一个 django 应用程序 并在用户上传文件时让它创建文件 我遇到的问题是试图弄清楚如何删除它们 我创建它们的代码看起来像 from google appengine api import f
  • 如何判断一个类型是否真正可移动构造

    以这段代码为例 include
  • 默认情况下.NET XmlIgnore?

    有没有办法让 XmlSerializer 默认忽略所有成员 除非我另有说明 我有一个基类和几个带有大量成员的派生类 但大多数我不想被序列化 只有少数几个可以接受序列化 不 你不能这样做 XmlSerializer 使用 选择退出 过程 它将
  • Google Play 服务会更新正在运行的应用程序吗?

    我正在 Google Play 上发布一个应用程序 该应用程序需要自动更新 该应用程序适用于信息亭 因此将在很长一段时间内保持打开和运行状态 而无需重新启动应用程序或重新启动设备 我的问题 Google Play 会更新当前正在运行的应用程
  • 使用列数可视化线图

    我有个问题 我有两列toDate and fromDate 我想直观地看到它们之间的差异linechart x 轴应该是月份 例如 1 2 3 4 等 y 轴应该是月份的计数 最后这应该是由what 不幸的是我没有得到想要的输出 数据框 i
  • 分割字符串。获取拆分 SQL Server 2005 的第一个值

    我有一张桌子叫TableReason有一个名为Reason Reason数据类型是varchar 100 并包含这样的值2 2 22 33 0 2对于一排 我需要为此表编写一个更新语句来完成 只需要用逗号分割的第一个值 即 只需要 2 个
  • mvc3 Ajax.ActionLink 和延迟 LoadingElementId 显示

    我有一个进度 div 它绝对位于网页顶部 当我单击 Ajax ActionLink 时 有时当请求 响应短暂时 我会看到它在顶部闪烁 如何添加延迟以使进度横幅在 500 毫秒内不显示 谢谢 这是工作代码 var showProgress f
  • 如何从 SwiftUI 中的列表获取屏幕行?

    我想放一个Text对于列表中的每个可见 屏幕边界内 行 其当前索引在所有可见行中 我这里有一个例子 如果我有一个一次显示 3 行的列表 并且最初我希望它显示如下 A 0 B 1 C 2 如果我向下滚动列表 A 走出屏幕 那么就会像 B 0
  • 如何仅通过 DynamoDB 中组合键的一部分进行查询?

    比方说 我有User正在写评论Products 用户和产品是具有自己的 id 的独立实体 Review是一个复合实体 由以下组成userId and productId 我创建了一个表review在 DynamoDB 中同时具有userId
  • 如何在对象的构造函数完成后立即触发事件?

    研究告诉我 从构造函数本身引发事件是不可行的 因为对象可能没有完全初始化 那么构造函数触发后我可以在哪里触发事件 您可以做的一件事是添加一个方法来处理其他后期任务 Friend Class FooBar Public Sub New you
  • 此计算机上未安装 Windows PowerShell 管理单元“Microsoft.Sharepoint.Powershell”?

    我是使用 powershell 的新手 我已经尝试解决这个问题几个小时了 但仍然无法使其工作 先决条件 使用 Windows 10 以管理员身份运行 Powershell ISE 但是当我使用 Add PSSnapin WebAdminis
  • Python VLC 实例全屏不起作用

    我对 Python 有点陌生 正在为连接运动传感器的 Raspberry Pi 开发一个应用程序 这个想法是把这个 Raspberry 放在一个房间里 在运动检测时 视频开始全屏播放 视频播放完毕后 我想让设备休眠 10 分钟 然后再次激活
  • Android Renderscript - 在 Renderscript 中旋转 YUV 数据

    根据我的讨论Camera2 api Imageformat yuv 420 888 旋转图像上的结果 https stackoverflow com questions 44652828 camera2 api imageformat yu
  • Jquery悬停淡入/淡出问题

    http www izrada weba com orso http www izrada weba com orso将鼠标悬停在链接 NENATKRIVENA TERASA 上时 子菜单和图像一起淡入 子菜单使用一些下载的脚本淡出 上面的
  • C++递归求数组最小值

    我有一个 C 编程类的作业 要求编写一个不使用静态变量的递归函数 原型如下 int findmin const int a int n 我的解决方案有效 对于非常小的数组 但是我认为 2 n 复杂性过高并且可以改进 在指定的标准内是否可以进
  • Plotly Dash 回调 | SchemaLengthValidationError - 预期 7,收到 8 或 Dash 回调的“输出”中使用了不存在的对象

    目标 再追加 1 个Output list Updates在帖子底部 我想要output marker symbol 从每个trace dict as line marker to a Plot在本地主机前端 发生错误是因为我还没有Outp