Last Saturday I met the guys from
RStudio at the
R in Finance conference in Chicago. I was curious to find out what RStudio could offer. In the past I have used mostly
Emacs +
ESS for editing R files. Well, and what a surprise it was. JJ, Joe and Josh showed me a preview of
version 0.96 of their software, which adds a close integration of
Sweave and
knitr to RStudio, helping to create dynamic web reports with the new R Markdown and R HTML formats more easily.
 |
Screen shot of RStudio with a knitr file (*.Rmd) in the top left window.
Notice also the integrated knitr button. |
You probably have come across Sweave in the past, but
knitr is a fairly new package by
Yihui Xie that brings
literate programming to a new level. In particular the
markdown approach allows me to create web content really quickly, without worrying to much about layout and R formatting. I begin to wonder if PDF and paper will be replaced by tablets and HTML5 in the future.
Here is a simple example. The
knitr source code is available on
Github.
Great post Markus :)
ReplyDeleteLooks awesome-- I'm newly discovering the wonders of knitr for the first time myself-- thanks for the examples!
ReplyDeleteFabulous examples! Thanks for exploring the new possibilities of knitr!
ReplyDeleteOne minor point: you can remove suppressPackageStartupMessages() and add a chunk option message=FALSE instead so people won't be too surprised by this super long function name :)
Thanks for pointing this out, and also for your knitr package.
ReplyDeleteI am quite new to this, though, your example was so well done that I was able to reproduce it. Is it possible to include latex tables in the output as well? When I attempted it the output was of latex code rather than latex output.
ReplyDeleteIf you had time for a simple example it would be appreciated.
Cheers,
Wes
Hi Wes, have you seen the following discussion entry?
ReplyDeletehttps://groups.google.com/group/knitr/browse_thread/thread/90acfbfc7a01e066?pli=1
Awesome post, I am going to try to build a dashboard based on what you showed.
ReplyDeleteAlso, there is indeed a spell checker built into RStudio, so you're all set with that.
Great example, and wonderful work! I got to reproduce in html previwed on Rstudio.
ReplyDeleteMy question is how you upload this page on blogspot (blogger)?
Did you just copy the body part of html and paste it on a blog post manually keeping
the image format as base64?
I did some experiments; Manually copying and pasting a part from head to the end of body instead of body part produces the (almost) identical display to what Rstudio produces. It even includes googlevis chart as it is designed to work! I don't know how that works but it's amazing. I wonder if there is a way to make this workflow a bit more automatic from Rstudio by typing a command in R console. There seems exit a way for Wordpress using Rwordpress package, but I have not found any posts for blogger.
ReplyDeleteThe easiest way for me is to host the HTML output from knitr on a public folder, e.g. via Dropbox, and to to include the page into a blog post via an iframe tag i nHTML. The googleVis package vignette has more details on this in section 3.3, see http://cran.r-project.org/web/packages/googleVis/vignettes/googleVis.pdf
ReplyDeleteExcellent examples. However, is there any way to get a stand-alone HTML file from and .Rhtml document via command-line operation? Using knit() always seems to create and HTML file that depends on external images.
ReplyDeleteHi Dylan,
ReplyDeleteUsing googleVis for the charts actually gets around your problem. The output of the above knitr file is just one html file. The charts are rendered in the browser. See also my example for a presentation done with knitr and googleVis: http://lamages.blogspot.co.uk/2012/05/interactive-html-presentation-with-r.html. The whole output is one html file only again.I hope this helps.Markus
Hello,
ReplyDeleteI am trying to run the code that you provide above and keep getting an error saying that the functions supressPackageStartupMessages and gvisScatterChart could not be found. Needless to say I was not able to produce the first interactive chart you provided as an example. I have both the knitr and googleVis packages installed and loaded. I am running the latest version of R Studio (0.96.316) and R (2.15.1). I also added the working directory to my list of trusted locations in the global security settings of Flash player as you suggested. Any help resolving this would be greatly appreciated.
Hi Enrique,
ReplyDeleteI believe you are trying to copy and paste the code from this post directly. You have to use the underlying source code, wich is hosted on GitHub. Here is the link agai, same as above https://gist.github.com/2704646
I hope this helps.
Markus
problem solved....coding error!
ReplyDeleteThanks! Now to learn pandoc...
ReplyDeleteHi Markus,
ReplyDeleteThank you for your brilliant posts!
copied and paste the code, everything is fine a part the motion chart!
I did make sure that the folder where I saved the html file is authorized by Flash, but no luck... This is a snapshot of what I see: just a blank space.
Any suggestion?
Cheers,
Alberto
Please send me the version details of R and googleVis, plus the R code and HTML output via email and I will take a look at it. I have only today uploaded version 0.3.3 of googleVis to CRAN, you may want to test your code with that version first.
ReplyDeleteHi Markus,
ReplyDeleteThis is a very useful post. Thanks for sharing!
I tried to re-create the report on my system. But I'm not getting the cool colored boxes with the formatted R codes inside them. I'm just getting plain text. Any clues why this is happening?
Thanks
Moe
Thanks for your timely response Markus! I did knit an Rmd file. I am using markdownToHTML() following a knit() call. The fragment.only parameter was set to TRUE. I changed it to FALSE and now I have the neat boxes:
ReplyDeletemarkdownToHTML("test.md", "test.html",fragment.only = FALSE)
problem solved. I should use knit2html as well and see how it works.
Keep up the great work
-Moe