Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

r - Embedding googleVis charts into a web site

Reading from the googleVis package vignette: "With the googleVis package users can create easily web pages with interactive charts based on R data frames and display them either via the R.rsp package or within their own sites". Following the instructions I was able to see the sample charts, using the plot method for gvis objects. This method by default creates a rsp-file in the rsp/myAnalysis folder of the googleVis package, using the type and chart id information of the object and displays the output using the local web server of the R.rsp package (port 8074 by default).

Could anybody help me (or provide some link) on the procedure someone has to follow in order to embed such charts into an existing web site (e.g. a joomla site)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Obviously I think that this is too verbose for @gd047, but I put a kind of tutorial since it maybe helpful for other readers who want to use googleVis on their own website.

install googleVis from CRAN

install.packages('googleVis')

pay attention to the messages.

then, create gvis object:

library(googleVis)
M <- gvisMotionChart(Fruits, "Fruit", "Year")

you can find the contents of M by:

> M

and you can find the plot on your browser:

> plot(M)

then, what is necessary to generate the chart is M$html$chart:

> M$html$chart
[1] "<!-- MotionChart ... omitted... ">
</div>
"

save it to a file:

> cat(M$html$chart, file="tmp.html")

if you open the "tmp.html" as a file (i.e, address says files:///***/tmp.html), then security warning may occur. What you need is to access the html via http://.

So if you can edit any web page where <script> tag is available (e.g., blogger), you can use it by simply copy and paste the contents of tmp.html, like this:

http://takahashik.blogspot.com/2011/01/googlevis-example.html

here is the famous "iris" version of example:

http://takahashik.blogspot.com/2011/01/googlevis-example-for-data-iris_10.html

Otherwise, if you have a web server, you can use it by uploading the tmp.html on the server.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...