View source: R/add_cell_message.R
add_cell_message | R Documentation |
Generates a JS function (wrapped with htmlwidgets::JS
) that,
given a record (rec
), returns an object with type
and message
.
add_cell_message(type = c("error", "warning", "info"), message = "message")
type |
A string that specifies the type of message.
One of |
message |
A string or JS expression. If it contains |
A htmlwidgets::JS
object containing a JavaScript function definition:
function(rec) { return { type: "<type>", message: <message> }; }
Use this within column_def()
for cell validation
set.seed(123)
iris_rows <- sample(nrow(iris), 10)
data <- iris[iris_rows, ]
# Simple warning
cheetah(
data,
columns = list(
Species = column_def(
message = add_cell_message(type = "info", message = "Ok")
)
)
)
# Conditional error using `js_ifelse()`
cheetah(
data,
columns = list(
Species = column_def(
message = add_cell_message(
message = js_ifelse(Species == "setosa", "", "Invalid")
)
)
)
)
# Directly using a JS expression as string
cheetah(
data,
columns = list(
Sepal.Width = column_def(
style = list(textAlign = "left"),
message = add_cell_message(
type = "warning",
message = "rec['Sepal.Width'] <= 3 ? 'NarrowSepal' : 'WideSepal';"
)
)
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.