2

I am developing a subscription based website that will supply custom financial trading indicators and I am in need of advice. Using the googleVis package on R, I export new charts ever 30 minutes in .html format that employ some limited Javascript for interactability. I originally looked into using Wordpress as my CMS due to ease of use and readily accessible subscription management plugins, but its limitations regarding Javascript make it so that I cannot complete the updates automatically. (I'd have to manually update the site every 30 minutes)

Consequently, I am now considering my other options. I briefly tried Joomla on my VPS, but it also seems to have a number of quirks regarding Javascript. I am only moderately experienced in developing sites, so I will have to rely on preexisting products for site construction and especially customer subscription management.

I realize this is a very open ended request, but I am just looking for some direction from those with more experience than myself. Any input would be greatly appreciated.

  • 2
    I do a lot of very similar work, building walled wordpress sites that offer searchable reporting for things like business intelligence, and survey analysis. Lately, I've been creating reporting in RStudio, using R Markdown Documents. Parsing the file with readlines() and then again with pandoc to clean out the crud and uploading it using RWordpress. The head of your wordpress theme should hold all calls to necessary javascript libraries, freeing you to do what you need in the body of your document. I don't see any reason why you couldn't use a similar process with an additional chron job. – Brandon Bertelsen Nov 29 '12 at 20:48
  • Are you grooming googleVis output with R Markdown, or some other output? I'm having serious trouble getting googleVis output to reliably show in a Wordpress post or page even without trying to automate it.I've tried a dozen different methods and even more plugins but Wordpress just doesn't like googleVis. I can get it to show as a widget or in the header/footer, but still strugling to get in the post. I could also output as a google gadget, but I'm still very uninformed about how they work. – Jonathan George Nov 29 '12 at 23:22
  • Try using something like results='asis' and print() instead of plot. Should give you the results you're looking for. Also, if you showed us what you have tried we may be able to help you get it working. – Brandon Bertelsen Nov 30 '12 at 02:14
  • To your second comment, you should also disable the visual editor. That breaks things quite frequently. – Brandon Bertelsen Nov 30 '12 at 04:36

1 Answers1

3

Here's a toy example of my process for you to play with:

Note, this has been updated to accomodate for wpautop. googleVis javascript is broken if you don't remove all spacing from the uploaded fragment. The below accomplishes this.

test.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")
```

Now you need a script that brings them all together that can be chron'd on your server with something like R /path/to/your/file.r Don't forget to turn on xmlrpc in your wordpress settings. You'll also have to remember to add a call to the javascript library in the head of your wordpress theme.

file.r // chron this file!

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)
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
  • I apologize for all the questions, I'm totally new to Wordpress. How do I add a call to javascript in the header of my site? – Jonathan George Nov 30 '12 at 20:50
  • Appearance > Themes > Editor > look for something like "header" add your ` – Brandon Bertelsen Nov 30 '12 at 21:19
  • I'm a statistician by trade, web development is almost entirely new to me. I may end up having to go that route, but that's partially why I'm trying to stick with Wordpress. – Jonathan George Nov 30 '12 at 21:49
  • When I enter any of the commands starting with "```' in Rstudio, I'm receiving a "Error: attempt to use zero-length variable name". I made sure to load knitr and markdown, what am I doing wrong? – Jonathan George Nov 30 '12 at 22:58
  • Thanks for continuing to help me with this. I've got everything working except the actual content of the post. When the script writes the post, it outputs the file extension as the text (In this case "C:/test.html") rather than the actual content of the file. How do I correct this? I'm getting there, slowly but surely haha. – Jonathan George Dec 01 '12 at 00:10
  • It's because I passed text to the description rather than the raw html, I'll update the example. Look at the post edits to see what I changed. – Brandon Bertelsen Dec 01 '12 at 00:58
  • Well I'm at a total loss. I got your code running in Rstudio, and the result is viewable at http://empiricalvisuals.com/?p=64 I'm not sure why it is showing part of the code, I disabled visual editor. It's worth noting that I am still unable to get any posts showing with javasdscript, even if I just paste googleVis's .html output directly into the editor. – Jonathan George Dec 02 '12 at 00:42
  • Looks like you're passing headers into the post and it's breaking everything that follows. In markdowntoHTML did you use fragment.only=TRUE? – Brandon Bertelsen Dec 02 '12 at 01:25
  • Send me an email at myfirstname @ mylastname . ca with your wordpress login and password (a temporary one) and the script you're uploading and i'll take a look. – Brandon Bertelsen Dec 02 '12 at 01:27
  • Also, I just checked and was in fact using fragment.only=TRUE. – Jonathan George Dec 02 '12 at 05:13