我想在 gt R 包创建的表中包含国家标志的图像
library(tibble)
library(gt)
df <- tibble(country = c("Italy","Wales"),
flag = c("images/flags/Italy.png","images/flags/Wales.png")
)
# example with hardcoded country
df %>%
gt() %>%
text_transform(
locations = cells_body(vars(flag)),
fn = function(x) {
country = "Wales"
local_image(
filename = paste0("images/flags/",country,".png")
)
}
)
将国家/地区硬编码到此代码中会产生输出 - 但显然总是重复相同的标志,而与国家/地区列的值无关
所以我正在寻找正确的方法来替换“威尔士”,并参考同一行的 vars(country)
TIA