<bdo id='Lh17E'></bdo><ul id='Lh17E'></ul>

    1. <legend id='Lh17E'><style id='Lh17E'><dir id='Lh17E'><q id='Lh17E'></q></dir></style></legend>

    2. <tfoot id='Lh17E'></tfoot>
    3. <i id='Lh17E'><tr id='Lh17E'><dt id='Lh17E'><q id='Lh17E'><span id='Lh17E'><b id='Lh17E'><form id='Lh17E'><ins id='Lh17E'></ins><ul id='Lh17E'></ul><sub id='Lh17E'></sub></form><legend id='Lh17E'></legend><bdo id='Lh17E'><pre id='Lh17E'><center id='Lh17E'></center></pre></bdo></b><th id='Lh17E'></th></span></q></dt></tr></i><div id='Lh17E'><tfoot id='Lh17E'></tfoot><dl id='Lh17E'><fieldset id='Lh17E'></fieldset></dl></div>

      <small id='Lh17E'></small><noframes id='Lh17E'>

      通过更新其他组件来更改 Dash 组件的可见性

      Changing visibility of a Dash Component by updating other Component(通过更新其他组件来更改 Dash 组件的可见性)
      <legend id='vNtxy'><style id='vNtxy'><dir id='vNtxy'><q id='vNtxy'></q></dir></style></legend>

            • <bdo id='vNtxy'></bdo><ul id='vNtxy'></ul>
                <tfoot id='vNtxy'></tfoot>
                  <tbody id='vNtxy'></tbody>
                <i id='vNtxy'><tr id='vNtxy'><dt id='vNtxy'><q id='vNtxy'><span id='vNtxy'><b id='vNtxy'><form id='vNtxy'><ins id='vNtxy'></ins><ul id='vNtxy'></ul><sub id='vNtxy'></sub></form><legend id='vNtxy'></legend><bdo id='vNtxy'><pre id='vNtxy'><center id='vNtxy'></center></pre></bdo></b><th id='vNtxy'></th></span></q></dt></tr></i><div id='vNtxy'><tfoot id='vNtxy'></tfoot><dl id='vNtxy'><fieldset id='vNtxy'></fieldset></dl></div>

                <small id='vNtxy'></small><noframes id='vNtxy'>

              • 本文介绍了通过更新其他组件来更改 Dash 组件的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要隐藏一些组件,例如通过单击复选框(例如,图表或表格).但是,该文档没有为此目的提供合适的部分.提前致谢!

                I need to hide some Components, for example by clicking on a checkbox (for example, a graph or a table). However, the documentation did not provide a suitable section for this purpose. Thanks in advance!

                推荐答案

                您可以将需要隐藏的组件放置在 html.div([]) 中并更改其'显示' 选项到回调中的'none'.回调应该有一个下拉列表作为 Inputhtml.div([]) 中的组件作为 Output.

                You could place the Component you need to hide inside an html.div([]) and change its 'display' option to 'none' in a callback. The callback should have e.g a Dropdown as Input and the Component inside the html.div([]) as Output.

                以下是仅包含一个下拉列表和一个基于下拉列表的值可见/隐藏的输入组件的网络应用程序.复制后应该可以直接使用:

                The following is a web app containing only a Dropdown and an Input Component that is visible/hidden based on the value of the Dropdown. It should work directly when copied:

                import dash
                from dash.dependencies import Input, Output
                import dash_core_components as dcc
                import dash_html_components as html
                
                app = dash.Dash('example')
                
                app.layout = html.Div([
                    dcc.Dropdown(
                        id = 'dropdown-to-show_or_hide-element',
                        options=[
                            {'label': 'Show element', 'value': 'on'},
                            {'label': 'Hide element', 'value': 'off'}
                        ],
                        value = 'on'
                    ),
                
                    # Create Div to place a conditionally visible element inside
                    html.Div([
                        # Create element to hide/show, in this case an 'Input Component'
                        dcc.Input(
                        id = 'element-to-hide',
                        placeholder = 'something',
                        value = 'Can you see me?',
                        )
                    ], style= {'display': 'block'} # <-- This is the line that will be changed by the dropdown callback
                    )
                    ])
                
                @app.callback(
                   Output(component_id='element-to-hide', component_property='style'),
                   [Input(component_id='dropdown-to-show_or_hide-element', component_property='value')])
                
                def show_hide_element(visibility_state):
                    if visibility_state == 'on':
                        return {'display': 'block'}
                    if visibility_state == 'off':
                        return {'display': 'none'}
                
                if __name__ == '__main__':
                    app.run_server(debug=True)
                

                请注意,如果在 html.div([]) 中放置了多个组件,则回调仍将仅更改其所在组件的 'display' 属性输出.因此,您可以将其他 Dash 组件放在同一个 Div 中,而不会影响它们的可见性.

                Note that if multiple Components are placed inside the html.div([]), the callback will still only change the 'display' property for the Component that it outputs. Thus, you could place other Dash Components inside the same Div without their visibility being affected.

                希望这能正确回答您的问题.

                Hope this answers your question properly.

                自从两年前给出这个答案以来,Dash 项目和用户文档已经有了很大的发展.文档现在展示了多种实现回调之间状态共享的方法,其中第一种方法是将数据存储在隐藏的 div 中,正如这个答案所建议的那样.

                The Dash project and the User Documentation has evolved quite a bit since this answer was given two years ago. The docs now show multiple ways of accomplishing the sharing of state between callbacks, the first of which is by storing data in a hidden div as this answer suggests.

                查看文档中的特定页面这里.

                See the particular page in the docs here.

                这篇关于通过更新其他组件来更改 Dash 组件的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                  <small id='r7no6'></small><noframes id='r7no6'>

                  <i id='r7no6'><tr id='r7no6'><dt id='r7no6'><q id='r7no6'><span id='r7no6'><b id='r7no6'><form id='r7no6'><ins id='r7no6'></ins><ul id='r7no6'></ul><sub id='r7no6'></sub></form><legend id='r7no6'></legend><bdo id='r7no6'><pre id='r7no6'><center id='r7no6'></center></pre></bdo></b><th id='r7no6'></th></span></q></dt></tr></i><div id='r7no6'><tfoot id='r7no6'></tfoot><dl id='r7no6'><fieldset id='r7no6'></fieldset></dl></div>
                    <bdo id='r7no6'></bdo><ul id='r7no6'></ul>

                  • <tfoot id='r7no6'></tfoot>

                          <tbody id='r7no6'></tbody>

                          <legend id='r7no6'><style id='r7no6'><dir id='r7no6'><q id='r7no6'></q></dir></style></legend>