Recently and perhaps too late, I discovered 3 very useful functions that can serve as a bridge from R Markdown and Shiny framework to publish directly to webpages, particularly to WordPress blog posts. Here are my findings:
-
- render_site(): This function allows to quickly generate websites from analysis reports. In it’s most basic implementation, it needs atleast two files, “_site.yml” and “index.Rmd”. The first file describes the menu structure of the website and the second file gives the title and can be used as an introductory page. Refer to this webpage for more details.
- knit2wp(): This function from “knitr” package allows to publish posts to a wordpress blog page directly from RStudio. Here is a sample R code with brief explanation on how to do this.
library(RWordPress) library(markdown) library(knitr) library(XMLRPC) options(WordPressLogin = c(userID = 'password'), WordPressURL = 'https://your_blog_URL/xmlrpc.php') knit2wp('index.Rmd', title = 'XYZ',action="newPost")
Steps:
-
- Install all required packages
- Replace “userID” and “password” by WordPress username and password
- Insert your blog URL. For example mine is www.amalag.com
- Replace “index.Rmd” with the name of markdown file you want to publish
- Caveat: Blog’s SSL certificate must not be expired! If it is expired, it is necessary to renew it from your blog’s host.
- iframe: This is a great way in html to embed Shiny apps already hosted on some other server. I use PSU server to host apps but you can always go with shinyapps.io. Here is the sample code to embed apps:
< iframe style="border: none; width: 900px; height: 500px;" src="shiny_app_url" width="300" height="150"></iframe>
Thanks for reading this post. If it was useful to you in any way, please leave a comment.
PS: this page was posted using knit2wp()