特定行的rhansontable变化背景 [英] rhandsontable change background of specific row

查看:101
本文介绍了特定行的rhansontable变化背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R Shining中使用了rhandsontable,我想在第一列中使用"Sum"更改行的颜色.由于行数不是固定的,因此无法根据行数选择求和"行.我已经尝试了所附的代码,但不幸的是,该代码无法正常工作.非常感谢您的帮助!

I'm using rhandsontable in R shiny and I would like to change the color of the row with "Sum" in the first column. Since the number of rows is not fixed, selecting the "Sum" row based in its row number does not work. I have tried the attached code, which unfortunately does not work. Many thank for your help !

library(shiny)
library(rhandsontable)
runApp(list(server=
  shinyServer(function(input, output, session) {

     CF_amt <- as.data.frame(matrix(0.0, nrow=5, ncol=10));
     CF_type <- data.frame(source = c("Row1","Row2","Row3","Row4","Sum"),
                            stringsAsFactors = FALSE);
     CF_names <- c("source","C1","C2","C3","C4","C5","C6","C7","C8","C9","C10");
     CF_tbl <- cbind(CF_type,CF_amt);

     values <- reactiveValues(data = CF_tbl)

     output$table <- renderRHandsontable({ 
       rhandsontable(values$data,rowHeaders = NULL,colHeaders=CF_names) %>% 
         hot_cols(fixedColumnsLeft = 1, renderer = "
             function (instance, td, row, col, prop, value, cellProperties) {
               Handsontable.renderers.TextRenderer.apply(this, arguments);
               if (col == 0) {
                td.style.background = '#F0F0F0';
               }
               else if(this.instance.getData()[row][0] == 'Sum'){
                td.style.background = '#F00000';
               }
            }"
       ) 
    })
  })
,ui=
  shinyUI(navbarPage("Test",
    tabPanel("HOT",
       fluidPage(fluidRow(
         column(12,rHandsontableOutput("table"))
      ))
   )
  ))
))

推荐答案

好像您遇到了JavaScript错误.尝试更改

Looks like you have a javascript error. Try changing

this.instance.getData()[row][0]

instance.getData()[row][0]

因为instance作为参数传递给渲染函数.

because instance is passed as parameter to your render function.

这篇关于特定行的rhansontable变化背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆