Plotly Dash:dash_bootstrap_components.Collapse 不折叠

Zep*_*hyr 2 javascript python callback collapse plotly-dash

我正在尝试dash_bootstrap_components.Collapse在我的dash应用程序中实现 a ,但它的行为存在问题。这里的代码,我不是自己写的,我只是从dash_bootstrap_components.Collapse 文档中复制过来的:

import dash
import dash_bootstrap_components as dbc
import dash_html_components as html
from dash.dependencies import Input, Output, State

app = dash.Dash()

app.layout = html.Div([dbc.Button('Open collapse',
                                  id = 'collapse-button',
                                  className = 'mb-3',
                                  color = 'primary'),
                       dbc.Collapse(dbc.Card(dbc.CardBody('This content is hidden in the collapse')),
                                    id = 'collapse')])


@app.callback(Output('collapse', 'is_open'),
              [Input('collapse-button', 'n_clicks')],
              [State('collapse', 'is_open')])
def toggle_collapse(n, is_open):
    if n:
        return not is_open
    return is_open

if __name__ == "__main__":
    app.run_server()
Run Code Online (Sandbox Code Playgroud)

这就是我得到的:

在此处输入图片说明

当我点击按钮时,没有任何反应。
我试图找出问题出在哪里,我发现:

  • napp.callback初始化为None,单击后变为1,然后随着1按钮点击次数的增加而增加,正确性
  • is_openapp.callback初始化为None,点击一次后仍然保持None,然后第二次点击后变成True,第三次点击后False,依此类推

我该怎么做才能让它发挥作用?

版本信息:

Python                    3.7.0
dash                      1.12.0
dash-bootstrap-components 0.10.1
dash-core-components      1.10.0
dash-html-components      1.0.3
dash-renderer             1.4.1
dash-table                4.7.0
plotly                    4.7.0
Run Code Online (Sandbox Code Playgroud)

Fla*_*ino 5

如果您链接 Boostrap 样式表,您的代码将按原样工作。

app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
Run Code Online (Sandbox Code Playgroud)