我正在使用rApache来显示在R中创建的封装好的图形,现在我只需要面对一个问题。如果文档中只有nest R代码,我认为HTML文件会呈现为某种png图像。
但是,我希望它被呈现为包含图形图的文档。因此,当我在<% ... %>标记之前或内部添加HTML时,我会得到一个破碎的图像符号作为输出。
我如何使它发生,我可以在HTML文档中使用绘图命令?
<h1> Plot Content </h1> // adding this causes a broken image
<%
setContentType("image/png")
t <- tempfile()
png(t,type="cairo")
rndDistribution <- rnorm(100)
plot(rndDistribution)
dev.off()
sendBin(readBin(t,'raw',n=file.info(t)$size))
unlink(t)
%>我的apache.conf:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/html/R>
SetHandler r-script
RHandler brew::brew
</Directory>发布于 2016-05-24 16:29:08
在阅读了一些关于在R中创建文件的内容之后,我找到了以下解决方案,作为一个非常简单的解决方案:
// 1. creating the image of the plotted diagramm:
<%
setwd("/var/www/html/images/R")
getwd()
png(filename="plot.png")
rndDistribution <- rnorm(100)
plot(rndDistribution)
dev.off()
%>
// 2. display graphic:
<h1> Plot Content </h1>
<img src="/images/R/plot.png">我想我尝试过的第一个代码示例是为文档的rather创建的,而不是特定目录中的r-script选项。
https://stackoverflow.com/questions/37418027
复制相似问题