Skip to contents

Set link formatter

Usage

set_formatter_link(
  widget,
  columns,
  label_field = NULL,
  url_prefix = NULL,
  url = NULL,
  target = "_blank",
  hoz_align = "left"
)

Arguments

widget

A tabulator() HTML widget.

columns

The names of the columns the formatter is applied to.

label_field

(character): Column to be used as label for the link.

url_prefix

(character): Prefix to add to the URL value.

url

(JavaScript function): A JavaScript function that return the URL value. The cell is passed to the function as its first argument. Use JS to pass JS code.

target

(character): Target attribute of the anchor tag.

hoz_align

(character): The horizontal alignment of the column.

Value

The updated tabulator() HTML widget

Examples

data <- data.frame(
  label = c("This is a link", "This is another link"),
  link = c("https://eoda.de", "https://eoda.de/data-science"),
  link2 = c("eoda.de", "github.com"),
  link3 = c("guinan", "data-science")
)

js_func <- "(cell) => `https://eoda.de/${cell.getValue()}`"

tabulator(data) |>
  set_formatter_link("link", label_field = "label") |>
  set_formatter_link("link2", url_prefix = "https://") |>
  set_formatter_link("link3", url = htmlwidgets::JS(js_func), label_field = "label")