【问题标题】:export widgets value into file with dash使用破折号将小部件值导出到文件中
【发布时间】:2020-04-21 03:53:43
【问题描述】:

我正在寻找一种解决方案来导出所有 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
...

有人知道我怎样才能成功吗?

【问题讨论】:

    标签: python flask plotly-dash


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-20
      相关资源
      最近更新 更多