material_switch: Create a shinymaterial switch

Description Usage Arguments See Also Examples

View source: R/shiny-material-switch.R

Description

Build a shinymaterial switch. The value is a boolean (TRUE if 'on', FALSE if 'off').

Usage

1
2
3
4
5
6
7
material_switch(
  input_id,
  off_label = "",
  on_label = "",
  initial_value = FALSE,
  color = NULL
)

Arguments

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".

See Also

update_material_switch

Examples

1
2
3
4
5
6
7
material_switch(
  input_id = "example_switch",
  off_label = "Off",
  on_label = "On",
  initial_value = TRUE,
  color = "#ef5350"
)

Example output

<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>

shinymaterial documentation built on Sept. 1, 2020, 1:07 a.m.