更改rhandsontable中列的字体颜色

Mal*_*nga 3 r rstudio rhandsontable

我有一个使用 Rhandsontable 渲染的表格。我想将特定列的字体颜色更改为红色。我该怎么做 ?我尝试了以下代码,但它不起作用

output$hot=renderRHandsontable({
rhandontable (table)%>%
hot_col("colum1", color = "red") 

})
Run Code Online (Sandbox Code Playgroud)

Tob*_*bel 7

如果您想更改表格内元素的样式(在您的情况下,它是给定列的每个单元格的字体颜色),您将需要使用一些 Javascript 并编写一个渲染器函数来完成这项工作,像这样:

# Toy data frame
table <- data.frame(a = 1:10, b = letters[1:10])

# Custom renderer function
color_renderer <- "
  function(instance, td) {
    Handsontable.renderers.TextRenderer.apply(this, arguments);
    td.style.color = 'red';
  }
"

rhandsontable(table) %>%
  hot_col("b", renderer = color_renderer)
Run Code Online (Sandbox Code Playgroud)

该函数color_renderer()保存为字符串并将用作-functionrenderer的参数hot_col()。请注意,我使用的参数td指的是表的单元格对象。td有几个属性,其中之一是style,而 style 又具有属性color。还要确保您使用的是正确的 Handsontable 渲染器。就我而言,它是一个TextRenderer,但您可以根据列的数据类型使用不同的渲染器。

有关更多信息,请参阅Handsontable 文档

我希望这有帮助。干杯