0

R で作成されたカプセル化されたプロットを表示するために rApache を使用しています。現在、直面しなければならない問題は 1 つだけです。ドキュメント内にネストされた 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>
4

1 に答える 1

0

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-script オプションではなく、ドキュメントの R-Handler 用に作成されたものだと思います。

于 2016-05-24T16:29:08.910 に答える