add_cell_message {cheetahR} | R Documentation |
Create a JavaScript cell message function for cheetahR widgets
Description
Generates a JS function (wrapped with htmlwidgets::JS
) that,
given a record (rec
), returns an object with type
and message
.
Usage
add_cell_message(type = c("error", "warning", "info"), message = "message")
Arguments
type |
A string that specifies the type of message.
One of |
message |
A string or JS expression. If it contains |
Value
A htmlwidgets::JS
object containing a JavaScript function definition:
function(rec) { return { type: "<type>", message: <message> }; }
Use this within column_def()
for cell validation
Examples
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';"
)
)
)
)
[Package cheetahR version 0.2.0 Index]