使用深色主题样式破折号组件 bootstrap css
Style dash components with dark-theme bootstrap css
下面是一个 plotly dash 应用程序的工作示例,它在选项卡上显示下拉菜单,然后在选择下拉菜单中的项目时显示提醒。
#!/usr/bin/env python3
import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash('Example', external_stylesheets=[dbc.themes.DARKLY])
app.title = 'Example'
app.layout = dbc.Tabs([
dbc.Tab(
dbc.Card([
dcc.Dropdown(id='dropdown',
options=[
{ 'label': 'Item 1', 'value': 'foo' },
{ 'label': 'Item 2', 'value': 'bar' },
],
),
html.Br(),
html.Div(id='item-display'),
], body=True), label='Tab 1')
])
@app.callback(
Output('item-display', 'children'),
[Input('dropdown', 'value')]
)
def display_item(v):
return dbc.Alert(f'You selected Item {value}', color='primary') if v else ''
if __name__ == '__main__':
app.run_server(debug=True)
我正在使用 bootswatch darkly theme。
我遇到的问题是我不知道如何使用 bootstrap 样式设置 dash_core_components.Dropdown
的样式。
如下图所示,dash_bootstrap_components
元素的样式全部按照 bootstrap 样式设置,但 Dropdown
不是,实际上文本是下拉菜单几乎无法阅读,因为它是非常浅色背景上的白色文本。
在深色样本中,下拉列表如下所示:
将鼠标悬停在选项上时,背景为 bootstrap "primary" 颜色:
如何根据 bootstrap 样式设置 dcc.Dropdown
样式?
我注意到你提出了问题on the Plotly forums as well and that in particular, the answer linked in one of the answers probably contains a useful starting point. What I did myself was a slight modification of this answer:添加一个assets/dropdown.css
,内容如下:
.Select-control {
background-color: #222 !important;
}
.Select.is-focused > .Select-control {
background-color: #222;
}
#school-input {
color: white;
}
.Select-value-label {
color: white;
}
.Select--single > .Select-control .Select-value, .Select-placeholder {
border: 1px solid grey;
border-radius: 4px;
}
.VirtualizedSelectOption {
background-color: #222;
color: white;
}
.VirtualizedSelectFocusedOption {
background-color: #222;
opacity: .7;
}
.Select.is-focused:not(.is-open) > .Select-control {
background-color: #222;
border-color: var(--primary);
box-shadow: none;
}
结果如下:
下面是一个 plotly dash 应用程序的工作示例,它在选项卡上显示下拉菜单,然后在选择下拉菜单中的项目时显示提醒。
#!/usr/bin/env python3
import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash('Example', external_stylesheets=[dbc.themes.DARKLY])
app.title = 'Example'
app.layout = dbc.Tabs([
dbc.Tab(
dbc.Card([
dcc.Dropdown(id='dropdown',
options=[
{ 'label': 'Item 1', 'value': 'foo' },
{ 'label': 'Item 2', 'value': 'bar' },
],
),
html.Br(),
html.Div(id='item-display'),
], body=True), label='Tab 1')
])
@app.callback(
Output('item-display', 'children'),
[Input('dropdown', 'value')]
)
def display_item(v):
return dbc.Alert(f'You selected Item {value}', color='primary') if v else ''
if __name__ == '__main__':
app.run_server(debug=True)
我正在使用 bootswatch darkly theme。
我遇到的问题是我不知道如何使用 bootstrap 样式设置 dash_core_components.Dropdown
的样式。
如下图所示,dash_bootstrap_components
元素的样式全部按照 bootstrap 样式设置,但 Dropdown
不是,实际上文本是下拉菜单几乎无法阅读,因为它是非常浅色背景上的白色文本。
在深色样本中,下拉列表如下所示:
将鼠标悬停在选项上时,背景为 bootstrap "primary" 颜色:
如何根据 bootstrap 样式设置 dcc.Dropdown
样式?
我注意到你提出了问题on the Plotly forums as well and that in particular, the answer linked in one of the answers probably contains a useful starting point. What I did myself was a slight modification of this answer:添加一个assets/dropdown.css
,内容如下:
.Select-control {
background-color: #222 !important;
}
.Select.is-focused > .Select-control {
background-color: #222;
}
#school-input {
color: white;
}
.Select-value-label {
color: white;
}
.Select--single > .Select-control .Select-value, .Select-placeholder {
border: 1px solid grey;
border-radius: 4px;
}
.VirtualizedSelectOption {
background-color: #222;
color: white;
}
.VirtualizedSelectFocusedOption {
background-color: #222;
opacity: .7;
}
.Select.is-focused:not(.is-open) > .Select-control {
background-color: #222;
border-color: var(--primary);
box-shadow: none;
}
结果如下: