Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust width of dropdown menu option in Dash-Plotly

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.

enter image description here

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')
    ])
])
like image 243
Prince Modi Avatar asked Jul 20 '20 04:07

Prince Modi


People also ask

Should dropdown options width be same as menu width?

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.

What is the default dropdown in DCC?

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.

How do I modify the chart in Plotly?

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

How do I disable a particular option inside the dropdown menu?

Disable Options To disable a particular option inside the dropdown menu, set the disabledproperty in the options.


Video Answer


1 Answers

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%"},
        ),
    ]
)
like image 110
lahsuk Avatar answered Oct 22 '22 09:10

lahsuk