I am trying to build an app using Dash in Python based on Plotly. I am having hard time in adjusting the width of Dropdown menu options. I have attached code and image below. I would like the width of Dropdown options to be same as the menu width.
app.layout = html.Div(children=[
html.H1(children='Welcome to Portfolio Construction Engine!'),
html.Div(children='What would you like to do?', style={
'font-style': 'italic',
'font-weight': 'bold'
}),
html.Div([
dcc.Dropdown(
id='demo-dropdown',
options=[
{'label': 'Upload Scores', 'value': 'upload_scores'},
{'label': 'Analyze Portfolios', 'value': 'analyze_portfoliio'},
{'label': 'Generate Data for IC Engine', 'value': 'gen_data_ic_engine'}
],
placeholder='Select a task...',
style={
'width': '50%'
}
),
html.Div(id='dd-output-container')
])
])
I would like the width of Dropdown options to be same as the menu width. Show activity on this post. While its correct to place width: 50% to change the width of the dropdown component, you've placed it in the inner component rather than the parent Div.
dcc.Dropdown For production Dash apps, Dash Core Components styling and layout should be managed with Dash Enterprise Design Kit. Default Dropdown An example of a default dropdown without any extra properties.
The updatemenu method determines which plotly.js function will be used to modify the chart. There are 4 possible methods: "restyle": modify data or data attributes "relayout": modify layout attributes
Disable Options To disable a particular option inside the dropdown menu, set the disabledproperty in the options.
While its correct to place width: 50%
to change the width of the dropdown component, you've placed it in the inner component rather than the parent Div.
app.layout = html.Div(
children=[
html.H1(children="Welcome to Portfolio Construction Engine!"),
html.Div(
children="What would you like to do?",
style={"font-style": "italic", "font-weight": "bold"},
),
html.Div(
[
dcc.Dropdown(
id="demo-dropdown",
options=[
{"label": "Upload Scores", "value": "upload_scores"},
{"label": "Analyze Portfolios", "value": "analyze_portfoliio"},
{
"label": "Generate Data for IC Engine",
"value": "gen_data_ic_engine",
},
],
placeholder="Select a task...",
# style={"width": "50%"}, NOT HERE
),
html.Div(id="dd-output-container"),
],
style={"width": "50%"},
),
]
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With