Two Dash controls side-by-side
Asked Answered
M

2

7

I am confused as to how to layout controls in dash. How do I put the dropdown and the datepicker on the same row side-by-side?

html.Div(
      [
        html.Div(
          [
            dcc.Dropdown(id='dropdown',
              options=[{'label': i, 'value': i} for i in all_options],
              multi=False,
               placeholder='Select Symbol...',
            ),
            dcc.DatePickerSingle(
              id='my-date-picker-single',
              min_date_allowed=today,
              max_date_allowed=today,
              initial_visible_month=today,
              date=today)
          ],
          className='row'
       ),
     ]
    ),
Meantime answered 13/2, 2018 at 18:44 Comment(0)
A
4

I think what you need is the style option of the elements you want to display side-by-side. Using style={'float': 'right','margin': 'auto'} on both of them.

html.Div(
      [
         html.Div(
          [
             dcc.Dropdown(id='dropdown',
                          options=[{'label': i, 'value': i} for i in all_options],
                          multi=False,
                          placeholder='Select Symbol...',
                          style={'float': 'right','margin': 'auto'}
             ),
             dcc.DatePickerSingle(id='my-date-picker-single',
                                  min_date_allowed=today,
                                  max_date_allowed=today,
                                  initial_visible_month=today,
                                  date=today
                                  style={'float': 'right','margin': 'auto'}
             )
          ],
      className='row'
   ),
 ]
),
Ascending answered 31/3, 2020 at 18:35 Comment(2)
Can you provide an example?Coconut
Thank you. I appreciate this. I did attempt this using an alternative method. I used bootstrap components. dash-bootstrap-components.opensource.faculty.ai/docs/components/…Coconut
M
-2

I think I figured it out. It looks correct:

html.Div(
  [
        dcc.Dropdown(id='dropdown',
            options=[{'label': i, 'value': i} for i in all_options],
            multi=False,
            placeholder='Select Symbol...'
        )
  ],
  className='two columns'
),
html.Div(
  [
        dcc.DatePickerSingle(
            id='my-date-picker-single',
            month_format='Y-M-D',
            min_date_allowed=today - timedelta(days=3),
            max_date_allowed=today + timedelta(days=730),
            initial_visible_month=today,
            date=today),
          html.Div(id='output-container-date-picker-single')
  ],
  className='two columns'
Meantime answered 13/2, 2018 at 20:0 Comment(2)
This seems to depend entirely on the CSS you're using, so this isn't helpful without having that.Bebel
Which css you are using?Coconut

© 2022 - 2024 — McMap. All rights reserved.