Hi guys,
I’m new to dash and for a dashboard I work on for a project there need to be a range slider and 2 input boxes that interact with each other.
Basically 2 requirements are;
- start and end values of range slider should be displayed in the input boxes, and update whenever i move the slider
- If I enter values in input boxes slider points have to be updated accordingly
I have included the basic code I’m working on now.
import dash
import dash_html_components as html
import dash_core_components as dcc
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
html.Div([
dcc.Input(id='start_value', type='text')
], id='start_value_div'),
dcc.RangeSlider(
id='my-range-slider',
min=0,
max=20,
step=0.5,
value=[5, 15]
),
html.Div([
dcc.Input(id='end_value', type='text')
], id='end_value_div')
])
# Display start value of range in input field
@app.callback(
dash.dependencies.Output('start_value_div', 'children'),
[dash.dependencies.Input('my-range-slider', 'value')])
def update_output(value):
return value[0]
# Display end value of range in input field
@app.callback(
dash.dependencies.Output('end_value_div', 'children'),
[dash.dependencies.Input('my-range-slider', 'value')])
def update_output(value):
return value[1]
# Display start & end value of input fields in range slider if user enters values
@app.callback(
dash.dependencies.Output('my-range-slider', 'value'),
[dash.dependencies.Input('start_value_div', 'children'),
dash.dependencies.Input('end_value_div', 'children')])
def update_output(start_value, end_value):
value = [start_value, end_value]
return value
if __name__ == '__main__':
app.run_server(debug=True)
What I currently get is a text area instead of input box and they don’t interact with the slider the way I want.
Is this possible in dash? Please help me with this