python - 如何将 Python Dash list 分成几列?

标签 python html css plotly-dash

我是 Dash 的初学者,我从来没有用 html 编写过代码,所以我不确定这一切是如何工作的。

我一直在尝试将 list 分成几列。

这是我的部分代码:

        html.Div(
                dcc.Checklist(className ='checkbox_1',
                        options=[
                            {'label': 'A1', 'value': 'I1ST1'},
                            {'label': 'A2', 'value': 'I2ST1'},
                            {'label': 'A3', 'value': 'I3ST1'},
                            {'label': 'A4', 'value': 'I4ST1'},
                            {'label': 'A5', 'value': 'I5ST1'},
                            {'label': 'A6', 'value': 'I6ST1'}
                                ],
                        values='I1ST1',
                        labelStyle = {'display': 'block'}
                                ),
            ),

            html.Div(
                dcc.Checklist(className ='checkbox_1',
                        options=[
                            {'label': 'B1', 'value': 'I1ST2'},
                            {'label': 'B2', 'value': 'I2ST2'},
                            {'label': 'B3', 'value': 'I3ST2'},
                            {'label': 'B4', 'value': 'I4ST2'},
                            {'label': 'B5', 'value': 'I5ST2'},
                            {'label': 'B6', 'value': 'I6ST2'}
                                ],
                        values='I1ST2',
                        labelStyle = {'display': 'block'}
                                )
            ),
            html.Div(
                dcc.Checklist(className ='checkbox_1',
                        options=[
                            {'label': 'C1', 'value': 'I1MT'},
                            {'label': 'C2', 'value': 'I2MT'},
                            {'label': 'C3', 'value': 'I3MT'}
                                ],
                        values='I1MT',
                        labelStyle = {'display': 'block'}
                                )
                    )       
                ]
            )

我目前有这样的东西:

☒ A1
☐ A2
☐ A3
☐ A4
☐ A5
☐ A6
☒ B1
☐ B2
☐ B3
☐ B4
☐ B5
☐ B6
☒ C1
☐ C2
☐ C3

我想要的是这样的:

☒ A1   ☒ B1   ☒ C1
☐ A2   ☐ B2   ☐ C2
☐ A3   ☐ B3   ☐ C3
☐ A4   ☐ B4
☐ A5   ☐ B5
☐ A6   ☐ B6

我尝试在 labelStyle 函数中添加一些 CSS 函数(float、width),但它们都不起作用。

我这样做是否正确?我该怎么办?

最佳答案

我们可以通过以下方式实现这一目标,

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

app = dash.Dash(__name__)


app.layout = html.Div([
    html.Div(
        style={'width':'5%', 'height':'100%','float':'left'},
        children=[
            dcc.Checklist(className ='checkbox_1',
                    options=[
                        {'label': 'A1', 'value': 'I1ST1'},
                        {'label': 'A2', 'value': 'I2ST1'},
                        {'label': 'A3', 'value': 'I3ST1'},
                        {'label': 'A4', 'value': 'I4ST1'},
                        {'label': 'A5', 'value': 'I5ST1'},
                        {'label': 'A6', 'value': 'I6ST1'}
                            ],
                    values=['I1ST1'],
                    labelStyle = {'display': 'block'}
                            ),
        ]
    ),
    html.Div(
        style={'width':'5%', 'height':'100%','float':'left'},
        children=[
            dcc.Checklist(className ='checkbox_1',
                    options=[
                        {'label': 'B1', 'value': 'I1ST2'},
                        {'label': 'B2', 'value': 'I2ST2'},
                        {'label': 'B3', 'value': 'I3ST2'},
                        {'label': 'B4', 'value': 'I4ST2'},
                        {'label': 'B5', 'value': 'I5ST2'},
                        {'label': 'B6', 'value': 'I6ST2'}
                            ],
                    values=['I1ST2'],
                    labelStyle = {'display': 'block'}
                            )
        ]
    ),
    html.Div(
        style={'width':'5%', 'height':'100%','float':'left'},
        children=[
            dcc.Checklist(className ='checkbox_1',
                    options=[
                        {'label': 'C1', 'value': 'I1MT'},
                        {'label': 'C2', 'value': 'I2MT'},
                        {'label': 'C3', 'value': 'I3MT'}
                            ],
                    values=['I1MT'],
                    labelStyle = {'display': 'block'}
                            )
        ]
    )
])


if __name__ == '__main__':
    app.run_server(debug=True)

我们可以使用 style 选项设置每个 dash 组件的样式,使用它我们可以自定义布局。

关于python - 如何将 Python Dash list 分成几列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56847745/

相关文章:

python - 是否可以使用 Python 进行部分继承?

python - mongoengine ReferenceField 的奇怪之处

javascript - 如何让 DOM/事件监听器知道新附加的节点?

html - Bootstrap 缩略图图像间距

html - img 的 1px 边框问题

css - flexbox 每行元素数量相等?

python |喀拉斯 |多变量预测

python - 使用 asyncio 和 contextvars 在 python 中的两个异步程序之间共享状态

jquery - 如果屏幕尺寸减小,导航栏不响应

javascript - 在 HTML 中使用函数 JavaScript 添加到变量