Building Dashboards with Dash and Plotly
Alex Scriven
Data Scientist
Some useful applications of user inputs:
number
inputs)search
or text
inputs)password
and email
/text
input)
A user input is a dash core components Input
type (dcc.Input
)
id
is required for callback usagetype
will default to text (more on this later!)placeholder
appears faded in the input box
dcc.Input(
id='my_input',
type='text',
placeholder="Enter your text")
Similar to previous input work:
df
subset using input
#@app.callback()
def update_plot(my_input):
df = data.copy(deep=True)
df = df[df['column'] == my_input]
fig = px.scatter(data_frame=df)
return fig
Dash offers useful input types:
'text'
, 'number'
, 'password'
, 'email'
'range'
produces a range slider'tel'
and 'url'
are for telephone numbers and website urls'search'
and 'hidden'
involve advanced browser interaction
The type
argument automatically sets some limitations.
email
type requires [email protected] formatdcc.Input(
id='my_input',
type='email',
placeholder="Enter your email")
Additional arguments for specific types help control input
number
type only allows numbersmin
and max
set numerical limitminLength
/ maxLength
for text
inputstext
type also has pattern
for regex validation
dcc.Input(
id='my_input',
type='number',
max=250)
We can turn off an input programmatically with disabled
Or we can force its usage with required
(Both are True/False arguments of dcc.Input()
)
dcc.Input(id='my_input', disabled=True)
dcc.Input(id='my_input', required=True)
A vital argument is debounce
: Determines callback trigger (on unfocus or 'Enter') versus as-you-type
debounce
is False
(callback as you type)R
, Re
, Red
, Redd
in turndcc.Input(id='my_input', type='text',
debounce=False)
Building Dashboards with Dash and Plotly