这是我的过程的玩具示例供您使用:
请注意,这已更新以适应 wpautop。如果您不从上传的片段中删除所有间距,则 googleVis javascript 会损坏。下面实现了这一点。
测试.Rmd
# Title
```{r}
suppressPackageStartupMessages(library(googleVis))
# From example(gvisBarchart)
df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32))
Bar1 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2"))
```
## GoogleVis Plot
```{r results='asis'}
print(Bar1, "chart")
```
现在您需要一个将它们组合在一起的脚本,该脚本可以在您的服务器上运行,例如R /path/to/your/file.r
不要忘记在您的 wordpress 设置中打开 xmlrpc。您还必须记住在您的 wordpress 主题的头部添加对 javascript 库的调用。
file.r // 计时这个文件!
library(RWordPress)
library(knitr)
library(markdown)
# Setup your Wordpress information
options(WordpressLogin = c('USERNAME'= "YOURPASS"),
WordpressURL = "http://web.address/xmlrpc.php")
knit("/path/to/test.Rmd","/path/to/test.md")
markdownToHTML("/path/to/test.md","/path/to/test.html",fragment.only=TRUE)
tmp <- getRecentPostTitles(100) # Hackish
id <- tmp$postid[which(tmp$title == title)] # Get id of same title post
post <- readLines("path/to/test.html")
# Trim Function Courtesy of
# http://stackoverflow.com/questions/2261079/whitespace-in-r
trim <- function (x) gsub("^\\s+|\\s+$", "", x)
post <- trim(post) # Dump whitespace
post <- post[-which(post == "")] # remove line breaks to avoid wpautop()
if(length(id) > 0) {
deletePost(postid)
}
newPost(
list(
description=paste(post,collapse="\n"),
title="Post Title",
),
publish=TRUE)