Description Usage Arguments See Also Examples
View source: R/shiny-material-switch.R
Build a shinymaterial switch. The value is a boolean (TRUE if 'on', FALSE if 'off').
1 2 3 4 5 6 7 | material_switch(
input_id,
off_label = "",
on_label = "",
initial_value = FALSE,
color = NULL
)
|
input_id |
String. The input identifier used to access the value. |
off_label |
String. The label for the 'off' position of the switch. |
on_label |
String. The label for the 'on' position of the switch. |
initial_value |
Boolean. Is the switch initially on? |
color |
String. The color of the switch. Leave empty for the default color. Visit https://materializecss.com/color.html for a list of available colors. This input requires using color hex codes, rather than the word form. E.g., "#ef5350", rather than "red lighten-1". |
1 2 3 4 5 6 7 | material_switch(
input_id = "example_switch",
off_label = "Off",
on_label = "On",
initial_value = TRUE,
color = "#ef5350"
)
|
<script>$(document).ready(function(){
var shinyMaterialSwitch = new Shiny.InputBinding();
$.extend(shinyMaterialSwitch, {
find: function(scope) {
return $(scope).find(".shiny-material-switch");
},
getValue: function(el) {
return $(el).val();
},
subscribe: function(el, callback) {
$(el).on("change.shiny-material-switch", function(e) {
callback();
});
},
unsubscribe: function(el) {
$(el).off(".shiny-material-switch");
}
});
Shiny.inputBindings.register(shinyMaterialSwitch);
});</script>
<div class="switch shiny-material-switch" id="example_switch_switch">
<label>
Off
<input type="checkbox" id="example_switch"checked/>
<span class="lever"></span>
On
</label>
</div>
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.