1

我无法使用formattable().

我希望有斜体的第二列(物种(科学) )。

我尝试了下面的代码,但什么也没发生(表格出现在图形窗口中,但没有斜体或警告)

formattable(table.species, 
        align =c("l","l","c"), list(`Species (scientific)` = formatter(
          "span", style = ~ style(color = "grey",font.weight = "italic"))))   

下面是我的表的代码。

Species_eng <- c("Lowland paca", "Agouti", "Nine-banded armadillo",
              "Common opossum", "Ocelot","Red brocket deer",
              "White-nosed coati", "Collared peccary" ,"Central American Spiny rat",
              "Northern tamandua")
Species_sc <- c("Cuniculus paca","Dasyprocta punctata",
                            "Dasypus novemcinxtus", "Didelphis marsupialis",
                            "Leopardus pardalis", "Mazama americana",
                            "Nasua narica","Peccari tajacu","Proechimys semispinosus",
                            "Tamandua mexicana")
weight <- c(8.0, 3.6, 4.2, 2.5, 11.9, 22.8, 3.9, 25.2, 0.4, 4.3)

table.species <- data.frame(cbind(Species_eng, Species_sc, weight))
table.species <- table.species %>%
  rename(`Species (Eng)` = Species_eng,
         `Species (Scientific)` = Species_sc,
         `Weight (kg)` = weight)
#rearrange rows in order of increasing weight
table.species$`Weight (kg)` <- as.numeric(paste(table.species$`Weight (kg)`))
rownames(table.species) = NULL
table.species <- table.species[order(as.integer
                                     (table.species$`Weight (kg)`),
                                     decreasing = FALSE), ]     
4

1 回答 1

3

用于font.style斜体。这应该有效:

formattable(table.species, 
            align =c("l","l","c"), list(`Species (Scientific)` = formatter(
              "span", style = ~ style(color = "grey",font.style = "italic"))))

为了将来参考,您可以对font.family(例如,“次”)和font.size(例如,“200%”)执行相同的操作。

另请注意,Species (Scientific)在 Scientific 中需要大写“S”以匹配列名。

带有物种灰色和斜体的表格

于 2019-09-14T19:47:40.767 回答