Create a JavaScript cell message function for cheetahR widgets
add_cell_message.Rd
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")
Value
A htmlwidgets::JS
object containing a JavaScript function definition:
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';"
)
)
)
)