小编Mad*_*Mad的帖子

Plotly Dash - dcc.Store 回调触发两次

我在使用 Plotly Dash 时遇到问题,组件触发的回调dcc.Store每次都会触发两次。请参阅下面的代码和示例输出代码,该代码基于 Dash 文档中的示例 ( https://dash.plot.ly/dash-core-components/store )。

任何人都可以解释这一点或建议解决方法来防止它吗?

最小工作示例代码:

import dash

import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Output, Input, State
from dash.exceptions import PreventUpdate

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Store(id='local', storage_type='local'),
    html.Div(html.Button('localStorage', id='local-button')),
    html.Div(0, id='local-clicks'),
])


@app.callback(Output('local', 'data'),
              [Input('local-button', 'n_clicks')],
              [State('local', 'data')])
def on_click(n_clicks, data):
    if n_clicks is None:
        raise PreventUpdate

    app.logger.info(f"Updating data store")

    data = data or {'clicks': 0}

    data['clicks'] = data['clicks'] + 1
    return data


@app.callback(Output('local-clicks', 'children'),
              [Input('local', …
Run Code Online (Sandbox Code Playgroud)

python plotly-dash

5
推荐指数
1
解决办法
2960
查看次数

标签 统计

plotly-dash ×1

python ×1