Upload plots as PNG file to your wordpress

Synopsis

Note! This post is a addition to Create blog posts from RStudio to WordPress

About a week ago I tried to add my blog to R-Bloggers. I thought everything was correct to add it. But this week I got a mail from Tal Galili (site administrator of R-Bloggers) with the message that my blog uses base64 images in my feed.

This type of images are created, as default option, with knitr as a standalone HTML document. It would be great if I could solve it with PNG instead of base64 images, even better if I could solve it with posting from RStudio to WordPress.

And so I did. In this post I will explain you how to post your WordPress post with PNG files and upload it to your blog.

How to recognize a base64 image

Well you can check your RSS feed of your blog and search for data:image/png;base64, it should be something like this (thx Tal for the image 🙂 ):

Setting your options

To upload your PNG files to your blog you need to set some knitr options first.

As I described in my earlier post you had to set your login parameters to login to your WordPress blog. For the upload of files to WordPress you need to set the upload.fun option of knitr. This will take the filename as the input and returns a link to the image in the RMarkdown file.

Let’s set the login parameters and the upload.fun options. I’ve hashed it out because I can not post to the dummy credentials. In the earlier post you can add the upload.fun option after your login credentials and you are good to go.

After setting the above credentials your are ready to upload your post with PNG image(s) to your blog. For the completeness I will post a png image in this post I will create within R.

Example of posting your PNG image

plot of chunk iris

After this I could start post to my blog with knit2wpCrayon.

Again I hashed it because it could not post itself.

This code can also be find on my GitHub.