【发布时间】:2016-03-17 07:21:51
【问题描述】:
我不知道为什么这是错误的。我基本上是在尝试使用 ggplot 在 HTML 模板上创建进度条。为此,我需要创建一个 for 循环并将其存储在 r 的 temp 文件夹中。然后将 png 文件编码为 base64 格式,以便我可以将其放在 HTML 图像标签上。
library(catools)
a <- seq(1:10)
1:length(a)
for (i in 1:length(a)){
total_questions <- 8
current_question<- i+1
group <- rbind("Total Questions", "Current question")
progress <- rbind(total_questions, current_question)
colnames(progress)<- "Progress"
progress <- as.data.frame(progress)
progress_bar <- cbind(group,progress)
# save example plot to file
png(tec <- tempfile(paste0("image",i), fileext = ".png"))
ggplot(progress_bar, aes(group, Progress,fill=group), height=1000, width=800) + geom_histogram(stat="identity")
dev.off()
# Base64-encode file
txt <- base64Encode(readBin(tec, "raw", file.info(tec)[1, "size"]), "txt")
txt
}
这是我的错误。
文件中的错误(con,“rb”):无法打开连接另外: 警告消息:在文件中(con,“rb”):无法打开文件 '/var/folders/w0/lrdx2zvn2hgf_ds0f92hpy500000gn/T//RtmpWD4Ysl/image114459476144.png': 没有这样的文件或目录
【问题讨论】:
-
不确定您的问题是什么,但使用
ggsave肯定会为您节省故障排除。以p <- ggplot(...); ggsave(tec, p, width=5, height=5)为例。 -
当我将
base64Encode替换为base64encode(在 Windows 上)时,它对我来说很好。 -
@antoine-sac 效果很好。谢谢!
-
所以把它写下来并标记它是正确的。
标签: r ggplot2 base64 temporary-files