在 dbc checklist – dash 中插入空格并包裹文本。

huangapple go评论64阅读模式
英文:

Insert space and wrap text in dbc checklist - dash

问题

I'm trying to increase the margin between the icon and text in a dbc checklist. The default setting has no space between text and the icon. When trying to insert a margin, the output has the text beneath the icon and text runs into the graph's. Is it possible to shift the text up in line with the icon and wrap the text so it runs on multiple lines?

import dash
from dash import dcc
from dash import html
import dash_bootstrap_components as dbc

external_stylesheets = [dbc.themes.SPACELAB, dbc.icons.BOOTSTRAP]

app = dash.Dash(__name__, external_stylesheets=external_stylesheets,suppress_callback_exceptions=True)

values = ['orange', 'black', 'purple', 'red', 'brown', 'yellow']
options = []

for i in values:
    options.append({'label': html.Div(i, style={"display": "inline", 'font-size': 15, 'color': 'white', "padding-left":"0.5rem"}), 'value': i})

cat_filter_box = html.Div(children=[
    html.Div(children=[
        html.Label('Nav Bar', style={'color':'white'}),
        dcc.Checklist(
            options = options,
            value = values,
            labelStyle = {"margin":"1rem"},
            style = {'display': 'flex'},
        ),
    ], className = "vstack gap-1 h-50", style = {'padding':'2rem'}
    )
])

app.layout = dbc.Container([
    dbc.Row([
        dbc.Col(html.Div(cat_filter_box, className = "bg-secondary h-100"), width = 2),
        dbc.Col([
            dbc.Row([
                dbc.Col(dcc.Graph()),
            ]),
        ], width = 5),
        dbc.Col([
            dbc.Row([
                dbc.Col(dcc.Graph()),
            ]),
        ], width = 5),
    ])
], fluid = True)

if __name__ == '__main__':
    app.run_server(debug=True, port=8052)
英文:

I'm trying to increase the margin between the icon and text in a dbc checklist. The default setting has no space between text and the icon. When trying to insert a margin, the output has the text beneath the icon and text runs into the graph's. Is it possible to shift the text up in line with the icon and wrap the text so it runs on multiple lines?

import dash
from dash import dcc
from dash import html
import dash_bootstrap_components as dbc

external_stylesheets = [dbc.themes.SPACELAB, dbc.icons.BOOTSTRAP]

app = dash.Dash(__name__, external_stylesheets=external_stylesheets,suppress_callback_exceptions=True)

values = ['orange', 'black', 'purple', 'red', 'brown', 'yellow']
options = []

for i in values: 
    options.append({'label': html.Div(i, style={"display": "inline", 'font-size': 15, 'color':'white', "padding-left":"0.5rem"}), 'value': i})


cat_filter_box = html.Div(children=[
    html.Div(children=[

        html.Label('Nav Bar', style = {'color':'white'}),
        dcc.Checklist(
            options = options,
            value = values,
            labelStyle = {"margin":"1rem"}, 
            style = {'display': 'flex'},
        ),

    ], className = "vstack gap-1 h-50",
    style = {'padding':'2rem'}
    )
])

app.layout = dbc.Container([
    dbc.Row([
        dbc.Col(html.Div(cat_filter_box, className = "bg-secondary h-100"), width = 2),
        dbc.Col([
            dbc.Row([
                dbc.Col(dcc.Graph()),
            ]),
        ], width = 5),
        dbc.Col([
            dbc.Row([
                dbc.Col(dcc.Graph()),
            ]),
        ], width = 5),
    ])
], fluid = True)


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

答案1

得分: 1

这是您提供的代码段的翻译部分:

我对Dash还不太熟悉但是如果我将"flex"设置为"labelstyle"并禁用复选框样式我可以得到预期的结果

cat_filter_box = html.Div(children=[html.Div(children=[html.Label('Nav Bar', style={'color':'white'}), dcc.Checklist(
options=options, value=values, labelStyle={'margin':'1rem', 'display': 'flex'},
# style = {'display': 'flex'},
),], className="vstack gap-1 h-50", style={'padding':'2rem'})])

请注意,我已经将HTML和Python代码进行了翻译,不包括具体的功能和解释。

英文:

I am still new to Dash, but if I set flex to labelstyle and disable the checkbox style, I get the intended result.

cat_filter_box = html.Div(children=[
    html.Div(children=[

        html.Label('Nav Bar', style = {'color':'white'}),
        dcc.Checklist(
            options = options,
            value = values,
            labelStyle = {"margin":"1rem", 'display': 'flex'}, 
            #style = {'display': 'flex'},
        ),

    ], className = "vstack gap-1 h-50",
    style = {'padding':'2rem'}
    )
])

在 dbc checklist – dash 中插入空格并包裹文本。

huangapple
  • 本文由 发表于 2023年3月23日 12:22:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75819227.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定