【问题标题】:Using plots within rApache在 rApache 中使用绘图
【发布时间】:2016-05-24 15:34:23
【问题描述】:

我正在使用 rApache 来显示在 R 中创建的封装图。现在我只需要面对一个问题。 如果文档中只有嵌套 R 代码,我认为 HTML 文件会呈现为某种单一的 png 图像。

但是,我希望将其呈现为包含图形的文档。因此,当我在<% ... %> 标签之前或之内添加 HTML 内容时,我会得到一个损坏的图像标志作为输出。

我怎样才能做到,我可以在 HTML 文档中使用 plot 命令?

<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>

【问题讨论】:

    标签: r rapache


    【解决方案1】:

    在阅读了一些关于在 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">
    

    我猜我尝试的第一个代码示例是为文档的 R-Handler 制作的,而不是特定目录中的 r-script 选项。

    【讨论】:

      猜你喜欢
      • 2011-08-06
      • 2010-12-09
      • 1970-01-01
      • 2012-03-26
      • 2011-08-06
      • 1970-01-01
      • 2012-01-09
      • 2011-08-06
      • 1970-01-01
      相关资源
      最近更新 更多