使用破折号将小部件值导出到文件中

export widgets value into file with dash

我正在寻找导出所有 dash 小部件的值的解决方案。

我已经能够创建一个普通的 txt/csv 文件,但我无法在脚本中捕获小部件值。 我可以改进回调以添加所有小部件,但它会在每次修改时触发保存(但是我可以使用 n_clicks 使其更智能)。

@app.callback(
    dash.dependencies.Output('is_saved', 'children'),
    [dash.dependencies.Input('save_bas', 'n_clicks'), ])
def save_file(n_clicks):
    """Decode and store a file uploaded with Plotly Dash."""
    name='file.csv'
    to_export = ['cturn', 'sh_turn', 'sh_pitch', 'dead_turn']
    with open(os.path.join(UPLOAD_DIRECTORY, name), "wb") as fp:
        for item in to_export:
            fp.write('{}:{}\n'.format(item, dash.dependencies.Output(item, 'value')).encode("utf8"))
    return 'As been saved at' if n_clicks!=0 else 'Not saved yet'

当我运行那些行时,文件内容:

item1:item1.value
item2:item2.value
...

有谁知道我如何才能成功?

我将使用 dash.dependencies.State 不触发回调并仍然获取小部件值 (see details here for State)