是否可以在破折号应用程序中进行外部(非破折号)按钮回调?

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

我有一个带按钮的html模板。让我们说它是非常重要的模板,我们不想重拍它。它包含一个按钮和一些日期输入。

另一方面,我有一个破折号应用程序,它只包含一个图形的布局。

我想要的是根据模板的外部输入而不是破折号布局更新此图表。

模板:

<!--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. 或者也许可以通过某种方式将此输入链接到仪表板布局?

对不起,破折号的新手,文档不是直截了当的。

plotly-dash
1个回答
0
投票

据我所知,它在版本0.41.0中还不可能

据我所知,Dash需要Dash组件才能在其回调中使用。如果您尝试使用未专门设置为Dash组件的组件,则它将不会连接到底层的React代码。 - @coralvanda

© www.soinside.com 2019 - 2024. All rights reserved.