{"id":707,"date":"2015-02-03T16:00:08","date_gmt":"2015-02-03T23:00:08","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=707"},"modified":"2015-02-03T16:00:08","modified_gmt":"2015-02-03T23:00:08","slug":"creating-elegant-html-presentations-that-feature-r-code-using-slidify","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2015\/02\/03\/creating-elegant-html-presentations-that-feature-r-code-using-slidify\/","title":{"rendered":"Creating elegant HTML presentations that feature R code (using slidify )"},"content":{"rendered":"<p>We recently overhauled our R workshop to improve the flow and add a little style. For several years we created workshop slides using Sweave, LaTeX and Beamer. The results were practical and the process worked fine but we needed something more flexible and more elegant. To that end, we ultimately used R markdown and and the R packages<code>slidify<\/code> and <code>knitr<\/code> (within RStudio) to creates slides that look more like this:<\/p>\n<p><iframe loading=\"lazy\" src=\"http:\/\/bl.ocks.org\/zross\/raw\/61f122f09cd1883fdc56\/\" width=\"650\" height=\"550\"><\/iframe><\/p>\n<p>instead of like this:<\/p>\n<p><a href=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/oldstyle.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-956\" src=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/oldstyle.png\" alt=\"oldstyle\" width=\"662\" height=\"498\" \/><\/a><\/p>\n<p>We thought it might be helpful to share the process we used:<\/p>\n<h2>1. Choosing the technology<\/h2>\n<p>Though powerful, I have never liked using LaTeX. I find it tedious and verbose. Given the flexibility and increasing popularity of HTML\/JavaScript frameworks for producing slides I was quickly convinced that this would be the way to go.<\/p>\n<p>From my perspective there were two options, both of which used R markdown and the R package <code>knitr<\/code> to knit together text and R code. There was the package <strong><a href=\"http:\/\/slidify.org\/\">slidify<\/a><\/strong> from Ramnath Vaidyanathan and there was <strong><a href=\"https:\/\/support.rstudio.com\/hc\/en-us\/articles\/200486468-Authoring-R-Presentations\">R presentation<\/a><\/strong> using RStudio. I spent a few hours comparing the two options. My sense was that going with the R presentation option would be a \u201csmarter\u201d choice given that RStudio has a lot of wind in its sails and would likely support R presentation for years to come. But in my initial experiments I found it harder to customize using the RStudio option and <code>slidify<\/code> seemed more flexible in it\u2019s ability to use different JavaScript frameworks so I opted to use this package.<\/p>\n<p><strong>Caveat:<\/strong> I am a big RStudio fan and I\u2019m the first to say that I did not do a comprehensive side-by-side comparison. These were my initial impressions based on a relatively quick review. I would definitely by interested in learning from others \u2014 please e-mail me with your experience.<\/p>\n<h2>2. Getting started<\/h2>\n<p>Slidify is hosted on GitHub and I found it easy to get started using the instructions on<a href=\"http:\/\/slidify.org\/start.html\">this page<\/a>. After installing and loading slidify you can run:<\/p>\n<pre><code class=\" hljs javascript\">author(<span class=\"hljs-string\">\"slides\"<\/span>)<\/code><\/pre>\n<p>to scaffold a new presentation in your working directory (within a new folder called, in this case, &#8220;slides&#8221;). It initializes a new git repository, creates a sample R markdown presentation (<code>index.Rmd<\/code>) and adds an assets folder with four subfolders (<code>css<\/code>, <code>img<\/code>, <code>js<\/code> and<code>layouts<\/code>) all of which are basically empty except for <code>css<\/code> which has one file called<code>ribbons.css<\/code> which is just sample CSS and can safely be deleted. Note that if you&#8217;re not comfortable using Git you can ignore those files (and they can be safely deleted). The<code>.gitkeep<\/code> files force Git to keep the empty directories, they can also be deleted if you&#8217;re not using Git.<\/p>\n<p>Here is what the initial scaffolding looks like:<\/p>\n<p><a href=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/folders.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-960\" src=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/folders.png\" alt=\"folders\" width=\"161\" height=\"261\" \/><\/a><\/p>\n<p>Here is what the default R markdown file (index.Rmd) looks like:<\/p>\n<pre><code class=\" hljs python\">---\ntitle       : \nsubtitle    : \nauthor      : \njob         : \nframework   : io2012        <span class=\"hljs-comment\"># {io2012, html5slides, shower, dzslides, ...}<\/span>\nhighlighter : highlight.js  <span class=\"hljs-comment\"># {highlight.js, prettify, highlight}<\/span>\nhitheme     : tomorrow      <span class=\"hljs-comment\"># <\/span>\nwidgets     : []            <span class=\"hljs-comment\"># {mathjax, quiz, bootstrap}<\/span>\nmode        : selfcontained <span class=\"hljs-comment\"># {standalone, draft}<\/span>\nknit        : slidify::knit2slides\n---\n\n<span class=\"hljs-comment\">## Read-And-Delete<\/span>\n\n<span class=\"hljs-number\">1.<\/span> Edit YAML front matter\n<span class=\"hljs-number\">2.<\/span> Write using R Markdown\n<span class=\"hljs-number\">3.<\/span> Use an empty line followed by three dashes to separate slides!\n\n--- .<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-comment\">#id <\/span>\n\n<span class=\"hljs-comment\">## Slide 2<\/span>\n<\/code><\/pre>\n<p>Note that the initial code between the two sets of three dashes is the front matter &#8211; also known as YAML (a recursive acronym that stands for &#8220;YAML Ain&#8217;t Markup Language&#8221;), and is used to create initial settings that I&#8217;ll discuss below.<\/p>\n<h2>3. Create a quick slide presentation using the defaults<\/h2>\n<p>To convert the sample R markdown file to an actual slide presentation you would run:<\/p>\n<pre><code class=\" hljs javascript\">slidify(<span class=\"hljs-string\">\"index.Rmd\"<\/span>)<\/code><\/pre>\n<p>Running slidify for the first time will install a new folder called <code>libraries<\/code> which includes your chosen JavaScript framework and code highlighter. The JS framework will be responsible for the overall look and feel of your presentation and the highlighter will add syntax highlighting to your actual code. In the sample file, the default framework is<code>io2012<\/code> and the highlighter is <code>highlight.js<\/code>.<\/p>\n<p>This process also converts the R markdown to markdown (a .md file) and then to HTML so that you now have an index.html file that you can look at in your browser.<\/p>\n<p>Here is the new file structure after running <code>slidify(index.Rmd)<\/code>:<\/p>\n<p><a href=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/folders2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-961\" src=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/folders2.png\" alt=\"folders2\" width=\"201\" height=\"428\" \/><\/a><\/p>\n<h2>4. Change the look and feel: frameworks<\/h2>\n<p>The framework you choose controls the general design of the presentation and there are quite a few frameworks you can choose from. To change frameworks you simply change the framework setting in the YAML.<\/p>\n<p>Personally, I like the RevealJS framework. You can take a look at an example presentation <a href=\"http:\/\/lab.hakim.se\/reveal-js\/#\/\">here<\/a>. I also cleaned up the YAML a little so it now looks like:<\/p>\n<pre><code class=\" hljs markdown\"><span class=\"hljs-horizontal_rule\">---<\/span>\ntitle       : R crash course\nframework   : revealjs\nhighlighter : highlight.js\nhitheme     : tomorrow \nwidgets     : []\nmode        : selfcontained\n<span class=\"hljs-header\">knit        : slidify::knit2slides\n---<\/span><\/code><\/pre>\n<p>If you re-run <code>slidify(\"index.Rmd\")<\/code> the slides will be updated with the new styles and the new framework&#8217;s components will be added to the frameworks folder. Note that the folder for any other frameworks that you experimented with will not be deleted (you need to keep this in mind if you are uploading the materials because you could end up with a lot of unused files).<\/p>\n<h2>5. Choose a syntax highlighter theme<\/h2>\n<p>The highlighter theme controls how your code is highlighted. There are <a href=\"https:\/\/highlightjs.org\/static\/demo\/\">dozens<\/a> of styles for the highlight.js highlighter. I prefer to use the &#8220;default&#8221; style (instead of the style called <code>tomorrow<\/code> which is the default in <code>slidify<\/code>) so I make this small change to the hitheme component in the front matter.<\/p>\n<h2>6. Add your slide content<\/h2>\n<p>Three dashes separate slides. Beyond this you create content in either markdown or in raw HTML. To add your R code you would include code chunks that look like this:<\/p>\n<pre><code class=\" hljs markdown\"><span class=\"hljs-code\">```<\/span>{r}\n<span class=\"hljs-header\">#R code goes here<\/span>\n<span class=\"hljs-code\">```<\/span><\/code><\/pre>\n<p>Here is an example of a couple of slides (note that <code>echo=5<\/code> tells <code>knitr<\/code> to execute all the code but only to show line 5).<\/p>\n<pre><code class=\" hljs php\">---\ntitle       : R crash course\nframework   : revealjs\nhighlighter : highlight.js\nhitheme     : <span class=\"hljs-keyword\">default<\/span> \nwidgets     : []\nmode        : selfcontained\nknit        : slidify::knit2slides\n---\n\n\n<span class=\"hljs-comment\">## Zev's new workshop slides<\/span>\n\nYou can write the slide in Markdown <span class=\"hljs-keyword\">and<\/span> HTML. This is **bold** (markdown) but this is also &lt;b&gt;bold&lt;\/b&gt; (html).\n\nYou might even <span class=\"hljs-keyword\">include<\/span> &lt;span style=<span class=\"hljs-string\">\"color:green; font-weight:bold\"<\/span>&gt;inline CSS.&lt;\/span&gt;\n\n---\n\n<span class=\"hljs-comment\">## Quick example with ggplot2<\/span>\n\n\n```{r, <span class=\"hljs-keyword\">echo<\/span>=<span class=\"hljs-number\">5<\/span>}\nlibrary(ggplot2)\ndata(diamonds)\ndiamonds&lt;-diamonds[sample(<span class=\"hljs-number\">1<\/span>:nrow(diamonds),<span class=\"hljs-number\">2000<\/span>),]\nggplot(diamonds, aes(carat, price))+geom_point(color=<span class=\"hljs-string\">\"firebrick\"<\/span>)\n```<\/code><\/pre>\n<p><iframe loading=\"lazy\" src=\"http:\/\/bl.ocks.org\/zross\/raw\/6874b12b774fac5b5dcc\/#\/slide-1\" width=\"700\" height=\"450\"><\/iframe><\/p>\n<h2>7. Higher level customization<\/h2>\n<h3>Custom CSS<\/h3>\n<p>I wanted to make minor tweaks to the RevealJS style like adding a little more space between the headings and the content and changing the color of the H3 headers. In order to do this you can add the style directly to the Rmd file enclosed in style tags:<\/p>\n<pre><code class=\" hljs xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">style<\/span>&gt;<\/span><span class=\"css\">\n<span class=\"hljs-class\">.reveal<\/span> <span class=\"hljs-tag\">h3<\/span> <span class=\"hljs-rules\">{\n    <span class=\"hljs-rule\"><span class=\"hljs-attribute\">color<\/span>:<span class=\"hljs-value\"> <span class=\"hljs-hexcolor\">#c1d192<\/span><\/span><\/span>;\n    <span class=\"hljs-rule\"><span class=\"hljs-attribute\">text-align<\/span>:<span class=\"hljs-value\"> left<\/span><\/span>;\n    <span class=\"hljs-rule\"><span class=\"hljs-attribute\">padding-bottom<\/span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">10<\/span>px<\/span><\/span>;\n    <span class=\"hljs-rule\"><span class=\"hljs-attribute\">font-family<\/span>:<span class=\"hljs-value\"> Impact, sans-serif<\/span><\/span>;\n<span class=\"hljs-rule\">}<\/span><\/span>\n<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">style<\/span>&gt;<\/span>\n<\/code><\/pre>\n<p>Or you can create a separate CSS file and add it to the folder <code>assets\/css<\/code>. <strong>If you create a CSS file and add it to this folder it will automatically be included<\/strong> when you run <code>slidify<\/code>again (you don&#8217;t need to reference it). This is the approach I used because I wanted multiple presentations to use the same CSS. Here is the location of the CSS file:<\/p>\n<p><a href=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/folders3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-970\" src=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/folders3.png\" alt=\"folders3\" width=\"173\" height=\"299\" \/><\/a><\/p>\n<h3>Custom Layouts<\/h3>\n<p>You may want some of your slides to have specific layouts. For example, I wanted a few of my slides to include a specific two-column layout. To do this you would first create a mustache template with your layout. Second you save the template in <code>assets\/layouts<\/code>. To use the layout in your slide presentation you reference your layout in the slides.<\/p>\n<p>Here is an example of a new layout for creating two columns. This is saved as an HTML file in <code>assets\/layouts<\/code> (called <code>twocol.html<\/code>):<\/p>\n<pre><code class=\" hljs xml\">---\nlayout: slide\n---\n{{{ slide.content }}}\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div<\/span> <span class=\"hljs-attribute\">style<\/span>=<span class=\"hljs-value\">'float:left;width:48%;'<\/span> <span class=\"hljs-attribute\">class<\/span>=<span class=\"hljs-value\">'centered'<\/span>&gt;<\/span>\n  {{{ slide.left.html }}}\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div<\/span> <span class=\"hljs-attribute\">style<\/span>=<span class=\"hljs-value\">'float:right;width:48%;'<\/span>&gt;<\/span>\n  {{{ slide.right.html }}}\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div<\/span>&gt;<\/span>\n  {{{ slide.fullwidth.html }}}\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">div<\/span>&gt;<\/span>\n<\/code><\/pre>\n<p><a href=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/folders4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-971\" src=\"http:\/\/zevross.com\/blog\/wp-content\/uploads\/2014\/11\/folders4.png\" alt=\"folders4\" width=\"163\" height=\"286\" \/><\/a><\/p>\n<p>In order to use this new layout you would use an <code>&amp;<\/code> followed by the new layout file name suffix next to the new slide dashes (yes, this is hard to follow, see the example below). Then you reference the layout pieces with <code>*** =XXX<\/code> where XXX is the name of the layout section. As an example, I created a new layout called <code>twocol.html<\/code> with three sections left, right and fullwidth. This is what the code for the slide looks like (included in the Rmd file):<\/p>\n<pre><code class=\" hljs markdown\"><span class=\"hljs-horizontal_rule\">--- &amp;twocol<\/span>\n\n<span class=\"hljs-header\">### Two column example<\/span>\n\n<span class=\"hljs-emphasis\">***<\/span> =left\nFirst plot\n<span class=\"hljs-code\">```<\/span>{r, echo=TRUE}\nggplot(diamonds, aes(carat, price))+geom_point(color=\"cadetblue\")\n<span class=\"hljs-code\">```<\/span>\n\n<span class=\"hljs-emphasis\">***<\/span> =right\nSecond plot\n<span class=\"hljs-code\">```<\/span>{r, echo=TRUE}\nggplot(diamonds, aes(carat, price, color=clarity))+geom_point()\n<span class=\"hljs-code\">```<\/span>\n\n<span class=\"hljs-emphasis\">***<\/span> =fullwidth\nNow I should go back to one column (fullwidth)\n<\/code><\/pre>\n<p>And here is what it looks like:<br \/>\n<iframe loading=\"lazy\" src=\"http:\/\/bl.ocks.org\/zross\/raw\/e55b5dc73a9a676c083b\/#\/slide-3\" width=\"700\" height=\"600\"><\/iframe><\/p>\n<h3>Incremental reveal text and lists<\/h3>\n<p>During a slide presentation you may want to gradually reveal elements on a slide. According to the docs you have two options. For a bulleted list you can use <code>&gt; *<\/code> and for paragraphs you can use <code>.fragment<\/code>. Both of these worked fine with the default framework (io2012) but the bullet option did not seem to work for RevealJS. It seemed to be a bug which I reported <a href=\"https:\/\/github.com\/ramnathv\/slidify\/issues\/401\">here<\/a>. The work-around until the bug gets fixed would be to add a reference to jQuery and then add the class fragment to the lists using jQuery. This is not ideal but it works &#8212; here is the full code including the jQuery reference and the addition of class fragments at the end:<\/p>\n<pre><code class=\" hljs xml\">---\ntitle       : R crash course\nframework   : revealjs\nhighlighter : highlight.js\nhitheme     : default \nwidgets     : []\nmode        : standalone\nknit        : slidify::knit2slides\n---\n\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">script<\/span> <span class=\"hljs-attribute\">src<\/span>=<span class=\"hljs-value\">\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.min.js\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">script<\/span>&gt;<\/span>\n\n## Zev's new workshop slides\n\nYou can write the slide in Markdown and HTML. This is **bold** (markdown) but this is also <span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">b<\/span>&gt;<\/span>bold<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">b<\/span>&gt;<\/span> (html).\n\nYou might even include <span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">span<\/span> <span class=\"hljs-attribute\">style<\/span>=<span class=\"hljs-value\">\"color:green; font-weight:bold\"<\/span>&gt;<\/span>inline CSS.<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">span<\/span>&gt;<\/span>\n\n---\n\n### Quick example with ggplot2\n\n\n```{r, echo=5}\n# the echo=5 tells knitr that I want all lines to run but only show #5\nlibrary(ggplot2)\ndata(diamonds)\ndiamonds<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">-diamonds[sample(1:nrow(diamonds),2000),]\nggplot(diamonds,<\/span> <span class=\"hljs-attribute\">aes<\/span>(<span class=\"hljs-attribute\">carat<\/span>, <span class=\"hljs-attribute\">price<\/span>))+<span class=\"hljs-attribute\">geom_point<\/span>(<span class=\"hljs-attribute\">color<\/span>=<span class=\"hljs-value\">\"firebrick\"<\/span><span class=\"hljs-value\">)<\/span>\n```\n\n<span class=\"hljs-attribute\">---<\/span> &amp;<span class=\"hljs-attribute\">twocol<\/span>\n\n### <span class=\"hljs-attribute\">Two<\/span> <span class=\"hljs-attribute\">column<\/span> <span class=\"hljs-attribute\">example<\/span>\n\n*** =<span class=\"hljs-value\">left<\/span>\n<span class=\"hljs-attribute\">First<\/span> <span class=\"hljs-attribute\">plot<\/span>\n```{<span class=\"hljs-attribute\">r<\/span>, <span class=\"hljs-attribute\">echo<\/span>=<span class=\"hljs-value\">TRUE}<\/span>\n<span class=\"hljs-attribute\">ggplot<\/span>(<span class=\"hljs-attribute\">diamonds<\/span>, <span class=\"hljs-attribute\">aes<\/span>(<span class=\"hljs-attribute\">carat<\/span>, <span class=\"hljs-attribute\">price<\/span>))+<span class=\"hljs-attribute\">geom_point<\/span>(<span class=\"hljs-attribute\">color<\/span>=<span class=\"hljs-value\">\"cadetblue\"<\/span><span class=\"hljs-value\">)<\/span>\n```\n\n*** =<span class=\"hljs-value\">right<\/span>\n<span class=\"hljs-attribute\">Second<\/span> <span class=\"hljs-attribute\">plot<\/span>\n```{<span class=\"hljs-attribute\">r<\/span>, <span class=\"hljs-attribute\">echo<\/span>=<span class=\"hljs-value\">TRUE}<\/span>\n<span class=\"hljs-attribute\">ggplot<\/span>(<span class=\"hljs-attribute\">diamonds<\/span>, <span class=\"hljs-attribute\">aes<\/span>(<span class=\"hljs-attribute\">carat<\/span>, <span class=\"hljs-attribute\">price<\/span>, <span class=\"hljs-attribute\">color<\/span>=<span class=\"hljs-value\">clarity))+geom_point()<\/span>\n```\n\n*** =<span class=\"hljs-value\">fullwidth<\/span>\n<span class=\"hljs-attribute\">Now<\/span> <span class=\"hljs-attribute\">I<\/span> <span class=\"hljs-attribute\">should<\/span> <span class=\"hljs-attribute\">go<\/span> <span class=\"hljs-attribute\">back<\/span> <span class=\"hljs-attribute\">to<\/span> <span class=\"hljs-attribute\">one<\/span> <span class=\"hljs-attribute\">column<\/span> (<span class=\"hljs-attribute\">fullwidth<\/span>)\n\n<span class=\"hljs-attribute\">---<\/span> \n\n&gt;<\/span> * One item\n&gt; * Two item\n\n.fragment This is a paragraph that also gets revealed incrementally.\n\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">script<\/span>&gt;<\/span><span class=\"javascript\">\n$(<span class=\"hljs-string\">'ul.incremental li'<\/span>).addClass(<span class=\"hljs-string\">'fragment'<\/span>)\n$(<span class=\"hljs-string\">'ol.incremental li'<\/span>).addClass(<span class=\"hljs-string\">'fragment'<\/span>)\n<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">script<\/span>&gt;<\/span>\n<\/code><\/pre>\n<p>Go to live slides in next section to see the result.<\/p>\n<h3>Incremental reveal R code<\/h3>\n<p>Incrementally revealing code was a lot tougher and did not seem to have a built in option and I will not go into extreme detail on how this was accomplished. In general, I re-wrote the knitr code hooks to allow me to add a <code>class=\"fragment\"<\/code> to code chunks.<a href=\"https:\/\/gist.github.com\/zross\/edb5d1e42998da286e17\">The code<\/a>, which is posted on GitHub as a gist, needs to be run in a code chunk in your slides. I reference this code at the beginning of the Rmd file (in a code chunk) and then I can write the code chunk like:<\/p>\n<pre><code class=\" hljs javascript\">```{r, <span class=\"hljs-keyword\">class<\/span>=<span class=\"hljs-string\">\"fragment\"<\/span>}\n# <span class=\"hljs-keyword\">this<\/span> is an R code chunk that will be revealed incrementally\nx&lt;-<span class=\"hljs-number\">1<\/span>:<span class=\"hljs-number\">10<\/span>\ny&lt;-rnorm(<span class=\"hljs-number\">10<\/span>)\n```<\/code><\/pre>\n<p><strong>CLICK ON THE BLANK SLIDE BELOW AND USE ARROW KEYS TO INCREMENTALLY REVEAL:<\/strong><\/p>\n<p><iframe loading=\"lazy\" src=\"http:\/\/bl.ocks.org\/zross\/raw\/25bfaf4b287bf18aaea9\/#\/slide-4\" width=\"700\" height=\"600\"><\/iframe><\/p>\n<h3>Incremental reveal R plots<\/h3>\n<p>I have not had the time to incorporate incremental reveal of R plots into the code described above for knitr hooks.<\/p>\n<h2>8. A couple of final notes<\/h2>\n<p>Finding details and answers to questions can be a challenge. There are a lot of different resources and I had a hard time figuring out what was the best one. There is <a href=\"http:\/\/zevross.com\/blog\/2014\/11\/19\/creating-elegant-html-presentations-that-feature-r-code\/slidify.org\">slidify.org<\/a>,<a href=\"http:\/\/zevross.com\/blog\/2014\/11\/19\/creating-elegant-html-presentations-that-feature-r-code\/slidify.github.io\">slidify.github.io<\/a>, <a href=\"http:\/\/zevross.com\/blog\/2014\/11\/19\/creating-elegant-html-presentations-that-feature-r-code\/ramnathv.github.io\/slidify\">ramnathv.github.io\/slidify<\/a>, <a href=\"http:\/\/zevross.com\/blog\/2014\/11\/19\/creating-elegant-html-presentations-that-feature-r-code\/github.com\/ramnathv\/slidify\">github.com\/ramnathv\/slidify<\/a> each one with different materials. For example, I had particular trouble finding the full set of possible choices for the YAML settings. What is the full list of frameworks that can be selected? Where can I find a good discussion of widgets? These are the types of questions that I had some trouble finding the answers to.<\/p>\n<p>Printing to PDF was a challenge (this is not related to <code>slidify<\/code>, per se). Slidify has a great option of allowing you to compile the slides in two ways &#8212; one is standalone and one is self contained. With self contained, all of the references and materials are locally hosted in folders so that you do not have to rely on the Internet. With standalone the images etc are all embedded in the HTML and all other references use CDNs. Nevertheless, as a fail safe I still wanted a PDF to provide to students. There is a description of how to do this at <a href=\"https:\/\/github.com\/hakimel\/reveal.js\/\">this link<\/a> but I found that it was not that straightforward. I needed to add some JavaScript, delete the print.css file and remove the Bootstrap reference among other things.<\/p>\n<h2>Summary<\/h2>\n<p>I found the R markdown, slidify, knitr, RevealJS combination to be a useful set of tools to create a nice set of slides. The overhaul of my workshop slides was not without challenges, I found incrementally revealing code to be particularly challenging, but I&#8217;m pleased with the final result and the first two-day workshop where I used the slides (at UCLA) went well and the slides seemed to be appreciated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We recently overhauled our R workshop to improve the flow and add a little style. For several years we created workshop slides using Sweave, LaTeX&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-707","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=707"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/707\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}