Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
rhandsontable更改特定行的背景_R_Shiny_Handsontable - Fatal编程技术网

rhandsontable更改特定行的背景

rhandsontable更改特定行的背景,r,shiny,handsontable,R,Shiny,Handsontable,我在R中使用rhandsontable,我想在第一列中用“Sum”更改行的颜色。由于行数不是固定的,因此根据行数选择“Sum”行不起作用。我已经尝试了附加的代码,不幸的是,它不起作用。非常感谢你的帮助 library(shiny) library(rhandsontable) runApp(list(server= shinyServer(function(input, output, session) { CF_amt <- as.data.frame(matrix(0.

我在R中使用rhandsontable,我想在第一列中用“Sum”更改行的颜色。由于行数不是固定的,因此根据行数选择“Sum”行不起作用。我已经尝试了附加的代码,不幸的是,它不起作用。非常感谢你的帮助

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"))
      ))
   )
  ))
))
库(闪亮)
图书馆(rhandsontable)
runApp(列表(服务器)=
shinyServer(功能(输入、输出、会话){

CF_amt看起来您有javascript错误。请尝试更改

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

因为
实例
作为参数传递给渲染函数


非常感谢!这就解决了问题。事实上,我想我也试过了。不过,现在它起作用了。非常感谢。@ChrisW您应该将这个答案标记为您问题的答案。
instance.getData()[row][0]