简体   繁体   中英

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?

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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