首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在rApache中使用地块

在rApache中使用地块
EN

Stack Overflow用户
提问于 2016-05-24 15:34:23
回答 1查看 220关注 0票数 0

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

但是,我希望它被呈现为包含图形图的文档。因此,当我在<% ... %>标记之前或内部添加HTML时,我会得到一个破碎的图像符号作为输出。

我如何使它发生,我可以在HTML文档中使用绘图命令?

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>


<Directory /var/www/html/R>
    SetHandler r-script
    RHandler brew::brew
</Directory>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-24 16:29:08

在阅读了一些关于在R中创建文件的内容之后,我找到了以下解决方案,作为一个非常简单的解决方案:

代码语言:javascript
复制
// 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选项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37418027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档