ItamarG
ItamarG

Reputation: 474

Dash range slider with input on each side

I am quite new to front-end development and HTML and I'm struggling to understand
how to order a range slider with two inputs in the same line when using Dash

I have tried to separate the html.Div,
Putting the components in the same Div without separating them
adjust the different parameters and some more
but I still can't get it to appear the way I want

what I want:
enter image description here

what I have:
enter image description here

My code (that reproduce what I have):

import dash
import dash_core_components as dcc
import dash_html_components as html

app.layout = html.Div([
    html.Div([
        html.Div([dcc.Input(
            id='slider-min-value',
            placeholder=str(min_value))],
            style={'width': '10%'}
        ),
        html.Div([dcc.RangeSlider(
            id='condition-range-slider',
            min=0,
            max=30,
            value=[10, 15],
            allowCross=False)],
            style={'width': '25%'}
        ),
        html.Div([dcc.Input(
            id='slider-max-value',
            placeholder=str(max_value))],
            style={'width': '10%'}
        ),
        ],
        style={'display': 'inline-block'})])

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


what do I need to do in order to get the rangeslider and the inputs to appear the way I want?

Upvotes: 3

Views: 8477

Answers (2)

ItamarG
ItamarG

Reputation: 474

Ok, using {"display": "grid", "grid-template-columns": "10% 40% 10%"} gave me what I wanted.
layout:

app.layout = html.Div(
    html.Div(
        [
            dcc.Input(type='text', value=min_value),
            dcc.RangeSlider(
                id='condition-range-slider',
                min=0,
                max=30,
                value=[10, 15],
                allowCross=False
            ),
            dcc.Input(type='text', value=max_value)
        ],
        style={"display": "grid", "grid-template-columns": "10% 40% 10%"}),
    style={'width': '20%'}
)


what I got:
enter image description here

Upvotes: 3

Lawliet
Lawliet

Reputation: 1592

You can try updating the html.Div style with 'float': 'left',

import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div(
    [
        html.Div(
            style={'width':'10%', 'float':'left', 'marginLeft': 20, 'marginRight': 20},
            children=[
                dcc.Input(id='slider-min-value')
            ]
        ),
        html.Div(
            style={'width':'50%', 'float':'left','marginLeft': 20, 'marginRight': 20},
            children=[
                dcc.RangeSlider(
                    id='condition-range-slider',
                    min=0,
                    max=30,
                    value=[10, 15],
                    allowCross=False
                )
            ]
        ),
        html.Div(
            style={'width':'10%', 'float':'left','marginLeft': 20, 'marginRight': 20},
            children=[
                dcc.Input(id='slider-max-value')
            ]
        ),


    ])

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

enter image description here

Upvotes: 1

Related Questions