我正在使用formattable,然后生成表格,并將其作為一個html widget粘貼到一個pdf檔案中,你可以從代碼中看到。然而,我想知道是否有辦法改變表格的行高!
library("htmltools")
library("webshot")
library(formattable)
DF <- data. frame(Ticker=c(""/span>, ""/span>, ""/span>, "IBM"/span>, "AAPL"/span>, "MSFT"/span>)。)
Name=c("道瓊斯", "S&P 500", "技術",
"IBM", "Apple", "Microsoft")。)
Value=accounting(c(15988.08, 1880.33, 50,
130.00, 97.05, 50.99)。)
Change=percent(c(-0.0239, -0.0216, 0.021,
-0.0219, -0.0248, -0.0399))
################################## FUNCTIONS ##################################。
unit.scale = function(x) (x - min(x)) / (max(x) - min(x))
export_formattable <- function(f, file, width = "100%"/span>, height = NULL,
background = "white", delay = 0.2)
{
w <- as.htmlwidget(f, width = width, height = height)
path <- html_print(w, background = background, viewer = NULL)
url <- paste0("file://", gsub("", "/", normalizePath(path))
webshot(url,
file = 檔案。
selector = ".formattable_widget",
延遲 = 延遲)
}
#################################### comment">############################## comment">###################。
FT <- formattable(DF, align =c("l","c","r", "c"), list(
Name=formatter("span",
style = x ~ ifelse(x == "Technology", style(font.weight = "bold"), NA)), #NOT APPLIED when we output to PNG with the function!
#Value = color_tile("white", "orange"),
值 = color_bar("orange" , fun = unit.scale
),
Change = formatter("span",
style = x ~ style(color = ifelse(x < 0 , "red", "green"), "font. size" = "18px")。)
x ~ icontext(ifelse(x < 0, "箭頭向下", "箭頭向上"), x)
)),
table.attr = 'style="font-size: 18px; font-family: Calibri";"')
融資
#OUTPUT the table in the document as an image!
export_formattable(FT,"/outputpath/FT.png"/span>)
正如你所看到的,行與行之間有相當大的差距,這在html檔案中是可以的,但在pdf中看起來很奇怪。我已經檢查了檔案和網路,沒有直接的答案。
我怎樣才能減少所有行的表格高度,即使我想不設定任何空間,并把行的內容碰撞 "接觸 "到分隔的行線。
uj5u.com熱心網友回復:
你可以去掉填充物,使行的高度盡可能的緊湊:
你可以去掉填充物。
library(tidyverse)
library(formattable)
library(htmlwidgets)
scores <- data.frame(id = 1:5,
prev_score = c(10, 8, 6, 8, 8) 。
cur_score = c(8, 9, 7, 8, 9) 。
change = c(-2, 1, 1, 0, 1))
formattable(scores) %>%
as.htmlwidget()%>%
prependContent(tags$style("td { padding: 0px !important;}") )
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/329853.html
標籤:
下一篇:iText7文本值被隱藏


