代码之家  ›  专栏  ›  技术社区  ›  SeGa

更改rhandsontable中的背景图像(或任何两个字的css属性)

  •  0
  • SeGa  · 技术社区  · 6 年前

    具有 rhandsontables 但不幸的是,它们都使用一个单字的css属性,比如 color background

    怎么样 喜欢 background-color , background-image font-size 等。?用点(.)替换连字符(-)不起作用。

    ReferenceError:左侧的赋值无效

    在这个代码示例中,我想指定一个线性渐变作为 背景图像 出现红色,但不显示渐变。

    library(rhandsontable)
    library(shiny)
    
    DF = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10], stringsAsFactors = FALSE)
    
    ui <- fluidPage(
      rHandsontableOutput("tbk")
    )
    
    server <- function(input, output) {
      output$tbk <- renderRHandsontable({
        rhandsontable(DF, width = 550, height = 300) %>%
          hot_cols(renderer = "
                   function (instance, td, row, col, prop, value, cellProperties) {
                   Handsontable.renderers.TextRenderer.apply(this, arguments);
    
                   if (value == 'F') {
                     td.style.background-image = 'linear-gradient(to right, transparent, green)';
                     td.style.color = 'red';
    
                   } else if(value == 'J') {
                     td.style.background = 'lightgreen';
    
                   } else if(value == 'A' | value == 'x') {
                    td.style.background = 'lightblue'}
                   }")
      })
    }
    
    shinyApp(ui, server)
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   SeGa    6 年前

    解决方法是去掉连字符和圆点,使 .

    background-image 变成 backgroundImage font-size 变成 fontSize

    library(rhandsontable)
    library(shiny)
    
    DF = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10], stringsAsFactors = FALSE)
    
    ui <- fluidPage(
      rHandsontableOutput("tbk")
    )
    
    server <- function(input, output) {
      output$tbk <- renderRHandsontable({
        rhandsontable(DF, width = 550, height = 300) %>%
          hot_cols(renderer = "
                   function (instance, td, row, col, prop, value, cellProperties) {
                     Handsontable.renderers.TextRenderer.apply(this, arguments);
                     if (value == 'F') {
                       td.style.backgroundImage = 'linear-gradient(to right, transparent, green)';
                       td.style.fontSize = '25px';
                       td.style.color = 'red';
    
                     } else if(value == 'J') {
                       td.style.background = 'lightgreen';
    
                     } else if(value == 'A' | value == 'x') {
                      td.style.background = 'lightblue'}
                   }")
      })
    }
    shinyApp(ui, server)
    

    enter image description here