A toggle represents a physical switch that allows someone to choose between two mutually exclusive options. For example, “On/Off”, “Show/Hide”. Choosing an option should produce an immediate result.
For more details and examples visit the official docs. The R package can not handle each and every case, so for advanced use cases you need to work using the original docs to achieve the desired result.
Toggle(...)
Toggle.shinyInput(inputId, ..., value = defaultValue)
updateToggle.shinyInput(
session = shiny::getDefaultReactiveDomain(),
inputId,
...
)
string
Text for screen-reader to announce as the name of the toggle.
IComponentAs<React.HTMLAttributes<HTMLElement>>
Render the root element as another type.
boolean
Checked state of the toggle. If you are maintaining state yourself, use this property. Otherwise use defaultChecked
.
IRefObject<IToggle>
Optional callback to access the IToggle interface. Use this instead of ref for accessing the public methods and properties of the component.
boolean
Initial state of the toggle. If you want the toggle to maintain its own state, use this. Otherwise use checked
.
boolean
Optional disabled flag.
boolean
Whether the label (not the onText/offText) should be positioned inline with the toggle control. Left (right in RTL) side when on/off text provided VS right (left in RTL) side when no on/off text. Caution: when not providing on/off text user may get confused in differentiating the on/off states of the toggle.
IKeytipProps
Optional keytip for this toggle
string | JSX.Element
A label for the toggle.
string
string
Text to display when toggle is OFF. Caution: when not providing on/off text user may get confused in differentiating the on/off states of the toggle.
string
(event: React.MouseEvent<HTMLElement>, checked?: boolean) => void
Callback issued when the value changes.
(checked: boolean) => void
string
Text to display when toggle is ON. Caution: when not providing on/off text user may get confused in differentiating the on/off states of the toggle.
'checkbox' | 'switch' | 'menuitemcheckbox'
(Optional) Specify whether to use the "switch" role (ARIA 1.1) or the checkbox role (ARIA 1.0). If unspecified, defaults to "switch".
IStyleFunctionOrObject<IToggleStyleProps, IToggleStyles>
Optional styles for the component.
ITheme
Theme provided by HOC.
library(shiny.fluent)
if (interactive()) {
shinyApp(
ui = div(
Toggle.shinyInput("toggle", value = TRUE),
textOutput("toggleValue")
),
server = function(input, output) {
output$toggleValue <- renderText({
sprintf("Value: %s", input$toggle)
})
}
)
}