Geo*_*tas 24 r google-visualization
从googleVis包中读取插图:"使用googleVis包,用户可以使用基于R数据帧的交互式图表轻松创建网页,并通过R.rsp包或在他们自己的网站中显示它们".按照说明我可以使用gvis对象的绘图方法查看示例图表.默认情况下,此方法使用对象的类型和图表ID信息在googleVis包的rsp/myAnalysis文件夹中创建一个rsp文件,并使用R.rsp包的本地Web服务器显示输出(默认为端口8074) ).
有人可以帮助我(或提供一些链接)有关必须遵循的程序,以便将这些图表嵌入到现有的网站(例如joomla网站)中吗?
koh*_*ske 27
显然我觉得这对于@ gd047来说太冗长了,但我提出了一种教程,因为它可能对其他想要在自己的网站上使用googleVis的读者有所帮助.
从CRAN安装googleVis
install.packages('googleVis')
Run Code Online (Sandbox Code Playgroud)
注意信息.
然后,创建gvis对象:
library(googleVis)
M <- gvisMotionChart(Fruits, "Fruit", "Year")
Run Code Online (Sandbox Code Playgroud)
你可以通过以下方式找到M的内容:
> M
Run Code Online (Sandbox Code Playgroud)
你可以在浏览器上找到情节:
> plot(M)
Run Code Online (Sandbox Code Playgroud)
那么,生成图表所需要的是M $ html $ chart:
> M$html$chart
[1] "<!-- MotionChart ... omitted... \">\n</div>\n"
Run Code Online (Sandbox Code Playgroud)
将其保存到文件中:
> cat(M$html$chart, file="tmp.html")
Run Code Online (Sandbox Code Playgroud)
如果您打开"tmp.html"作为文件(即地址显示文件:///***/tmp.html),则可能会出现安全警告.你需要的是通过http://访问html.
因此,如果您可以编辑<script>标签可用的任何网页(例如,博客),您只需复制并粘贴tmp.html的内容即可使用它,如下所示:
http://takahashik.blogspot.com/2011/01/googlevis-example.html
这里是着名的"虹膜"版本的例子:
http://takahashik.blogspot.com/2011/01/googlevis-example-for-data-iris_10.html
否则,如果您有Web服务器,则可以通过上载服务器上的tmp.html来使用它.
如果你想手动将图表复制并粘贴到CMS(例如Joomla/Wordpress网站),那么你可以从'gvis'对象的html列表中复制并粘贴图表.就像@kohske建议的那样:
# demo data from manual
M <- gvisMotionChart(Fruits, "Fruit", "Year")
# write the HTML body to a temporary file without header and footer
cat(M$html$chart, file="temp.html")
# or with caption included:
cat(paste(M$html[c("chart", "caption")], collapse="\n"), file="temp.html")
Run Code Online (Sandbox Code Playgroud)
然后将temp.html的内容复制并粘贴到您的Joomla网站.您应该注意将代码粘贴为HTML内容,而不是在WYSIWYG编辑器(例如Tiny MCE)中!
如果您想在单独的页面上显示它,请不要忘记包括页眉和页脚:
# demo data from manual
M <- gvisMotionChart(Fruits, "Fruit", "Year")
# write the HTML to a temporary file with header and footer all included
cat(paste(M$html, collapse="\n"), file="temp.html")
Run Code Online (Sandbox Code Playgroud)
最后:您可以轻松地将此文档上传到例如ftp服务器并通过任何浏览器访问它.