【发布时间】: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.
- 那么,有没有办法让它工作?
- 是否可以使用 iframe?
- 或者也许可以通过某种方式将此输入链接到仪表板布局?
抱歉,dash 新手,文档不是那么直截了当。
【问题讨论】:
-
据我所知,Dash 需要在其回调中使用 Dash 组件。如果您尝试使用未专门设置为 Dash 组件的组件,则它不会连接到底层 React 代码。
-
我猜你是对的,感谢@coralvanda 的澄清
标签: plotly-dash