rhandsontable - 如何使用 rhandsontable 根据另一个单元格值格式化单元格
问题描述
我是 rhandsontable 包的新手,我正在尝试根据另一个单元格中的值突出显示一个单元格。当 mpg==21 时,我想突出显示 mtcars 数据集中“齿轮”列中的值。我不知道如何do.Apreciate some help in rhandsontable
rhandsontable(mtcars, readOnly = TRUE, width = 750, height =
300)%>%hot_cols(renderer = "
function (instance, td, row, col , prop, value,
cellProperties) {
Handsontable.renderers.NumericRenderer.apply(this, arguments);
var col_value = instance.getData()[XXXXXXXXXXX][XXXXXXXXX]
if (col_value ==21) {
td.style.background = 'pink';
}else if (col_value !=21) {
td.style.background = 'green';
}
}")
我不确定如何编写上面的代码来实现我的结果
解决方案
以下代码完成了工作:
library(rhandsontable)
ui <- fluidPage(
rHandsontableOutput('hot')
)
server <- function(input, output, session) {
output$hot <- renderRHandsontable({
rhandsontable(mtcars, readOnly = TRUE, width = 750, height = 300) %>%
hot_cols(renderer = myrenderer)
})
myrenderer <- "function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if (col == 9 && instance.getData()[row][0] == 21 ) {
td.style.background = 'pink';
}
}"
}
shinyApp(ui = ui, server = server)
推荐阅读
- python - 将超链接换行到列中的现有文本
- go - 程序失败:write tcp broken pipe 错误
- javascript - 如何禁用/隐藏和更改 CK 编辑器图像弹出窗口中的某些元素
- python - 如何覆盖继承层次结构中的函数?
- jquery - Jquery根据多个单选按钮组选择显示/隐藏div
- html - 如何在 div 的顶部和底部实现重复的 SVG?
- amazon-web-services - AWS DMS mysql 到 DDB 阵列
- python-3.x - 使用 io 在 python 中将字节传递给 ffmpeg
- php - 使用 POST PHP 方法传递值
- c# - 通过 AutoCAD 2021 实验室工作,不确定实验室 #5 要求我做什么