Skip to contents

Set toggle switch formatter

Usage

set_formatter_toggle_switch(
  widget,
  columns,
  size = 20,
  on_value = "on",
  off_value = "off",
  on_truthy = FALSE,
  on_color = "green",
  off_color = "red",
  clickable = TRUE
)

Arguments

widget

A tabulator() HTML widget.

columns

The names of the columns the formatter is applied to.

size

(numeric): The size of the switch in pixels.

on_value

(character): The value of the cell for the switch to be on.

off_value

(character) The value of the cell for the switch to be off.

on_truthy

(bool): Whether to show the switch as on if the value of the cell is truthy.

on_color

(character): The color of the switch if it is on.

off_color

(character): The color of the switch if it is off.

clickable

(bool): Enable switch functionality to toggle the cell value on click.

Value

The updated tabulator() HTML widget

Examples

data <- data.frame(
  Language = c("R", "Python", "Julia"),
  Available = c("yes", "yes", "no")
)

tabulator(data) |>
  set_formatter_toggle_switch("Available", on_value = "yes", off_value = "no")