【问题标题】:Is it possible to have external (non-dash) button callback in dash app?仪表板应用程序中是否可以有外部(非仪表板)按钮回调?
【发布时间】:2019-04-22 10:14:05
【问题描述】:

我有一个带有按钮的 html-template。假设它是非常重要的模板,我们不想重新制作它。它包含一个按钮和一些日期输入。

另一方面,我有 dash 应用程序,它的布局中只包含一个图表。

我想要的是根据来自我的模板的外部输入来更新这个图表,而不是从破折号布局。

模板:

<!--Template-->
{%config%}

<input type="datetime-local" name="dateTimeLocalStart" id=SelectionFrom/>
<input type="datetime-local" name="dateTimeLocalEnd" id=SelectionTo/>
<button type="button" id="show_new_data">SHOW</button>

{%app_entry%}
{%scripts%}
{%renderer%}

仪表板布局:

app.index_string = template_file.read() # is this a way?

# the basic dash layout
app.layout = html.Div(children=[
    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': 'Mo'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

但是如果我想像这样在破折号中回调它

@app.callback(
    Output(component_id="example-graph", component_property="figure"),
    [Input(component_id="show_new_data", component_property="id")]
)
def update_graph():
    print("Update graph callback")
    return "" # this never happens

我希望回调能够工作,但得到了这个:

dash.exceptions.NonExistentIdException: 
Attempting to assign a callback to the
component with the id "show_new_data" but no
components with id "show_new_data" exist in the
app's layout.
  1. 那么,有没有办法让它工作?
  2. 是否可以使用 iframe?
  3. 或者也许可以通过某种方式将此输入链接到仪表板布局?

抱歉,dash 新手,文档不是那么直截了当

【问题讨论】:

  • 据我所知,Dash 需要在其回调中使用 Dash 组件。如果您尝试使用未专门设置为 Dash 组件的组件,则它不会连接到底层 React 代码。
  • 我猜你是对的,感谢@coralvanda 的澄清

标签: plotly-dash


【解决方案1】:

据我了解,在 0.41.0 版中还不可能

Dash 需要 Dash 组件在其回调中使用,尽我所能 知识。如果您尝试使用未专门设置的组件 作为 Dash 组件,则不会连接到底层 反应代码。 – @coralvanda

【讨论】:

    猜你喜欢
    • 2022-07-14
    • 2020-06-13
    • 2010-12-29
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 2014-12-23
    相关资源
    最近更新 更多