在没有回调状态的情况下访问破折号应用程序表单输入值
Access dash app form input value without callback state
我正在开发一个 dash 应用程序,我有一个动态表单组是根据用户上传的 JSON 元数据创建的。
我的问题是我只有用户上传后的表单输入 ID,所以我无法在服务器启动时为我的回调装饰器中的每个输入定义状态 ID。
@self.parent_app.callback(
Output('output-div', 'children'),
[Input('button_submit', component_property='n_clicks')],
[State("form-input-0", "value"),..., State("form-input-n", "value")] # I can't do this
)
按下 button_submit 时,我必须访问所有表单数据才能创建输出。
我的问题是:
还有另一种方法可以在不使用回调中的状态的情况下访问我的表单的输入值吗?
没有其他直接方法可以访问表单的输入值。但是,您应该能够通过 pattern matching callbacks 实现您想要的。您的回调类似于,
from dash.dependencies import ALL
@self.parent_app.callback(
Output('output-div', 'children'),
[Input('button_submit', component_property='n_clicks')],
[State(dict(name="form-input", idx=ALL), "value")])
并且动态生成的表单输入应该具有表单的 ID
dict(name="form-input", idx=i)
其中 i
通常是一个整数。
我正在开发一个 dash 应用程序,我有一个动态表单组是根据用户上传的 JSON 元数据创建的。
我的问题是我只有用户上传后的表单输入 ID,所以我无法在服务器启动时为我的回调装饰器中的每个输入定义状态 ID。
@self.parent_app.callback(
Output('output-div', 'children'),
[Input('button_submit', component_property='n_clicks')],
[State("form-input-0", "value"),..., State("form-input-n", "value")] # I can't do this
)
按下 button_submit 时,我必须访问所有表单数据才能创建输出。
我的问题是: 还有另一种方法可以在不使用回调中的状态的情况下访问我的表单的输入值吗?
没有其他直接方法可以访问表单的输入值。但是,您应该能够通过 pattern matching callbacks 实现您想要的。您的回调类似于,
from dash.dependencies import ALL
@self.parent_app.callback(
Output('output-div', 'children'),
[Input('button_submit', component_property='n_clicks')],
[State(dict(name="form-input", idx=ALL), "value")])
并且动态生成的表单输入应该具有表单的 ID
dict(name="form-input", idx=i)
其中 i
通常是一个整数。