An example of a default toggle switch without any extra properties.
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, html, Input, Output, callback
import dash_daq as daq
app = Dash()
app.layout = html.Div([
daq.ToggleSwitch(
id='my-toggle-switch',
value=False
),
html.Div(id='my-toggle-switch-output')
])
@callback(
Output('my-toggle-switch-output', 'children'),
Input('my-toggle-switch', 'value')
)
def update_output(value):
return f'The switch is {value}.'
if __name__ == '__main__':
app.run(debug=True)
Make the switch display vertically by setting .
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
import dash_daq as daq
daq.ToggleSwitch(
vertical=True
)
Adjust the size of the toggle switch with size
.
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
import dash_daq as daq
daq.ToggleSwitch(
size=100
)
Add a label to the toggle switch and specify its position using label
and labelPosition
.
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
import dash_daq as daq
daq.ToggleSwitch(
label='My toggle switch',
labelPosition='bottom'
)
Our recommended IDE for writing Dash apps is Dash Enterprise’s
Data Science Workspaces,
which has typeahead support for Dash Component Properties.
Find out if your company is using
Dash Enterprise.
id
(character; optional):
The ID used to identify this compnent in Dash callbacks.
value
(logical; default FALSE
):
The state of the switch.
size
(numeric; optional):
The size of the switch.
color
(character; optional):
Color to highlight button/indicator.
vertical
(logical; default FALSE
):
If TRUE, switch will be vertical instead of horizontal.
disabled
(logical; optional):
If TRUE, switch cannot be clicked.
theme
(named list; default light
):
Theme configuration to be set by a ThemeProvider.
label
(named list; optional):
Description to be displayed alongside the control. To control styling,
pass an object with label and style properties.
label
is a character | named list with keys:
label
(character; optional)
style
(named list; optional) | unnamed list of characters | named list with keys:
label
(character; optional)
style
(named list; optional)s
labelPosition
(a value equal to: ‘top’ or ‘bottom’; default 'top'
):
Where the component label is positioned.
className
(character; optional):
Class to apply to the root component element.
style
(named list; optional):
Style to apply to the root object.
persistence
(logical | character | numeric; optional):
Used to allow user interactions in this component to be persisted when
the component - or the page - is refreshed. If persisted
is truthy
and hasn’t changed from its previous value, a value
that the user
has changed while using the app will keep that change, as long as the
new value
also matches what was given originally. Used in
conjunction with persistence_type
.
persisted_props
(unnamed list of values equal to: ‘value’; default ['value']
):
Properties whose user interactions will persist after refreshing the
component or the page. Since only value
is allowed this prop can
normally be ignored.
persistence_type
(a value equal to: ‘local’, ‘session’ or ‘memory’; default 'local'
):
Where persisted user changes will be stored: memory: only kept in
memory, reset on page refresh. local: window.localStorage, data is
kept after the browser quit. session: window.sessionStorage, data is
cleared once the browser quit.