【问题标题】:How to format a cell based on another cells value using rhandsontable如何使用 rhandsontable 根据另一个单元格值格式化单元格
【发布时间】:2019-06-16 06:21:39
【问题描述】:

我是 rhandsontable 包的新手,我正在尝试根据另一个单元格中的值突出显示一个单元格。我想在 mpg==21 时突出显示 mtcars 数据集中“齿轮”列中的值。我没有任何线索如何做。感谢 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';
  }
             }")

我不知道如何编写上面的代码来实现我的结果

【问题讨论】:

    标签: rhandsontable


    【解决方案1】:

    下面的代码完成了工作:

    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)
    

    【讨论】:

    • 如何检查列中的最大值或特定单元格中的值以进行验证?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 2014-10-12
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多