简体   繁体   English

在 R 中使用 formattable 的图标不会出现在数据表中

[英]Icon doesn't appear in datatable using formattable in R

I have some problems with the visualization of arrow-up and arrow-down icons while using the library formattable.在使用库格式表时,我在向上箭头和向下箭头图标的可视化方面遇到了一些问题。 Basically the arrows are not displayed while running the following code.运行以下代码时,基本上不会显示箭头。

 library(readr)
    library(dplyr)
    library(formattable)
    library(tidyverse)
    
    df1 <- data.frame(DATES = c("2020/11/20", "2020/12/20", "2021/01/20", "2021/02/20", "2021/03/20", "2021/04/20",
                                "2021/05/20", "2021/06/20", "2021/07/20", "2021/08/20", "2021/09/20", "2021/10/20",
                                "2021/11/20"),
                      UTILIZATION = round(c(0.00, 0.00, 0.00015, 0.00, 0.00, 0.00010, 0.005, 0.001, 0.00, 0.323, 0.4427, 0.00, 0.00),digits=2))
              
    df1$TREND <- sapply(1:nrow(df1),
                        function(i) {
                          if (i-12 > 0) mean(df1$UTILIZATION[i-1:2]) / mean(df1$UTILIZATION[i-3:12]) 
                          else NA_real_
                        } )
    
    
    result <- df1[13, ]
    result<-result %>% select(TREND)
    result$TREND <- result$TREND %% 1
    result
    
    
    






formattable(result, list(
     TREND = formatter(
        "span",
        style = x ~ style(color = ifelse(x < 0 , "red", "green")),
        x ~ icontext(ifelse(x < 0, "arrow-down", "arrow-up"), x)))
    )

Do you have any suggestions or any other solutions how to get the arrows displayed?您对如何显示箭头有任何建议或任何其他解决方案吗? While running the code everything is displayed right except the icons, which are getting displayed as a rectangle.运行代码时,除了图标之外,所有内容都显示正确,图标显示为矩形。

The arrow is displayed with your code.箭头与您的代码一起显示。 See here.看这里。 Do you mean something else?你的意思是别的吗?

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM