是否可以在 dash 应用程序中进行外部(非破折号)按钮回调?
Is it possible to have external (non-dash) button callback in dash app?
我有一个带按钮的 html-模板。假设它是非常重要的模板,我们不想重新制作它。它包含一个按钮和一些日期输入。
另一方面,我有 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.
- 那么,有没有办法让它发挥作用?
- Iframe 可以吗?
- 或者可能 link 以某种方式将此输入设置为破折号布局?
抱歉,dash 新手,文档不是那么直截了当。
据我了解,在 0.41.0 版本中还不可能
Dash needs Dash components for use in its callbacks, to the best of my
knowledge. If you try to use a component that isn't specifically set
up as a Dash component, then it won't be hooked up to the underlying
React code. – @coralvanda
我有一个带按钮的 html-模板。假设它是非常重要的模板,我们不想重新制作它。它包含一个按钮和一些日期输入。
另一方面,我有 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.
- 那么,有没有办法让它发挥作用?
- Iframe 可以吗?
- 或者可能 link 以某种方式将此输入设置为破折号布局?
抱歉,dash 新手,文档不是那么直截了当。
据我了解,在 0.41.0 版本中还不可能
Dash needs Dash components for use in its callbacks, to the best of my knowledge. If you try to use a component that isn't specifically set up as a Dash component, then it won't be hooked up to the underlying React code. – @coralvanda