Skip to content

Instantly share code, notes, and snippets.

@kohske
Created June 1, 2012 22:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohske/2855525 to your computer and use it in GitHub Desktop.
Save kohske/2855525 to your computer and use it in GitHub Desktop.
Rmd for slidify
```{r setup, echo = FALSE}
opts_knit$set(out.format = 'html')
opts_chunk$set(highlight = TRUE)
```
# Slidify
超簡単スライド作成
@kohske
---
### マークダウンからスライドを作成しましょう
このスライドの元になってるRmdはこちら
https://gist.github.com/2855525
---
### 手軽に資料を作りましょう
- markdown!!
- knitr!!
- slidify
やばいレベル。
---
### インストール
```{r f19, eval=FALSE}
library(devtools)
install_github('slidify', 'ramnathv')
```
以下も必要かも。
```{r f26, eval=FALSE}
install_github('knitr', 'yihui')
install_github('whisker', 'edwindj')
install_github('markdown', 'rstudio')
```
---
### コード評価ももちろんオーケー
```{r f31, prompt = TRUE, comment = NA}
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
coef(lm.D9)
```
---
### プロットもオーケー
```{r f32, warning=FALSE, fig.height=5}
par(family = "sans")
curve(sin(x), -10, 10, main = "正弦波")
```
---
### ggplot2もオーケー
```{r f33, warning=FALSE, fig.height=5}
library(ggplot2)
ggplot(NULL, aes(c(-10, 10))) + stat_function(fun=sin)
```
---
## これはいいね。おしまい。
```{r setup, echo = FALSE}
library(knitr)
library(grid)
opts_knit$set(out.format = 'html')
```
---
# Markdown, Knitr, and Slidify
state-of-the-art report/presentation generation in R
## @kohske
---
### Easy, fun, and beautiful
```{r ch1, echo=TRUE, fig.align='right', fig.height=5, fig.width = 5, dev ='png', dev.args = list(bg="transparent")}
txt <- rep(c("E", "a", "s", "y"), 10)
grid.text(txt, 0.5+sin(2*pi*seq_along(txt)/length(txt))/2.2, 0.5+cos(2*pi*seq_along(txt)/length(txt))/2.2, gp = gpar(fontsize = 30, col = rainbow(length(txt))))
```
---
### Reproducible
#### Freedom from
- Hand working
- Copy and paste
- Tweaking graphics by hand
#### All you need is
- Data
- Code
- Text
- Picture
---
### Tools
All tools are available for free.
- [R][link_R]: environment for data analysis
- [knitr][link_knitr]: report generation tool for R
- [slidify][link_slidify]: HTML5 slide generator
[link_R]: http://www.r-project.org/
[link_knitr]: http://yihui.name/knitr/
[link_slidify]: http://ramnathv.github.com/slidify/
- [Rstudio][link_rstudio]: excellent support for knitr.
[link_rstudio]: http://rstudio.org/
![R logo](figure/r-logo.png)
---
### Step-by-step tutorial
1. Prepare data
2. Write a code for data analysis
3. Write a code for summary output
4. Write a code for visualization
5. Knit them
6. Publish
---
### 1. Prepare data
Ok, use `iris`.
```{r ch3}
head(iris)
```
Of course, you may use data from your own experiment.
---
### 2. Write a code for data analysis
summary of `iris`
```{r ch4}
summary(iris)
```
---
### 2. Write a code for data analysis
Old-fashioned statistical test.
```{r ch5}
library(reshape2)
library(plyr)
iris2 <- melt(iris)
dlply(iris2, .(variable), function(x) pairwise.t.test(x$value, x$Species))
```
---
### 3. Write a code for summary output.
- For presentation, figures are better
- For report, [static html][link_static] version with detailed information may be better
[link_static]: http://kohske.github.com/sandbox/slidify/why-slidify/whyslidify_static.html
---
### 4. Visualization
```{r ch6, fig.width=9, fig.height=5.5}
library(ggplot2)
ggplot(iris2, aes(variable, value, colour = Species)) +
geom_boxplot() + theme_grey(base_size=24)
```
---
### 5. Markdown
You can knit text, codes, and pictures in a [markdown][mdofficial] file.
[mdofficial]: http://daringfireball.net/projects/markdown/
Here is the [markdown file][link_md] that [generates][link_generator] this slide.
[link_md]: http://kohske.github.com/sandbox/slidify/why-slidify/whyslidify.Rmd
[link_generator]: http://kohske.github.com/sandbox/slidify/why-slidify/generator.R
Then, all you need is:
- generate html
```{r ch7, eval = FALSE}
knit2html("whyslidify.Rmd")
```
- generate HTML5 slide
```{r ch8, eval = FALSE}
slidify("whyslidify.Rmd")
```
---
### 6. Publish
- Upload the html and relevant files.
- Let your boss or your client know the url.
---
### How to install
```{r ch9, eval = FALSE}
install.packages('devtools')
library(devtools)
install_github('slidify', 'ramnathv')
install_github('knitr', 'yihui')
install_github('whisker', 'edwindj')
install_github('markdown', 'rstudio')
```
- [Rstudio][link_rstudio] supports knitr.
- It also provides a space for publication of knitted report, [Rpubs][link_rpubs].
[link_rpubs]: http://www.rpubs.com/
[link_rstudio]: http://rstudio.org/
@ramnathv
Copy link

ramnathv commented Jun 3, 2012

Thanks for trying out slidify. Let me know if you have any feedback or suggestions. I am putting together a wiki page consisting of demos of slidify in use. Would you mind if I added a link to your presentation and the source?

Moreover, if you want to get better syntax highlighting, add the following chunk at the top of your Rmd file

opts_knit$set(out.format = 'html')
opts_chunk$set(highlight = TRUE)

Now, you can call slidify with the options highlighter = "R" and histyle = "acid" (or any of the themes listed in knit_theme$get().

@kohske
Copy link
Author

kohske commented Jun 3, 2012

@ramnathv Thanks for your great work!!!

Would you mind if I added a link to your presentation and the source?

Sure!!

And thanks for the advice. It will help me a lot.

@kohske
Copy link
Author

kohske commented Jun 3, 2012

@ramnathv
Copy link

ramnathv commented Jun 7, 2012

I screwed up while doing some commits to github. As a result, I renamed the old repository to slidify-old. You can find the new repository at slidify. I noticed that you have a fork. Hopefully you haven't made any significant changes. Would you mind forking the new repository since I will be deleting the old one in a bit?

@kohske
Copy link
Author

kohske commented Jun 7, 2012

Thanks for letting me know that. The output slide is somewhat different from the previous version, e.g., I cannot find the title page.

@ramnathv
Copy link

ramnathv commented Jun 7, 2012

Can you point me to your source file? I can quickly tell you what would fix it.

@ramnathv
Copy link

ramnathv commented Jun 7, 2012

Actually, I think I know what would fix it. Add a --- before the title slide. I changed the code a bit to use --- as a slide starter rather than just a separator. This allows for some pretty powerful manipulations later on. Try it and let me know if it solves your issue.

And nice post on twitter. I am working on a few things which would allow you to publish your presentation to RPubs in slide format. If folks at RStudio like it, maybe they might consider incorporating it into RStudio so that you can do one-click publishing.

Please post any feedback or suggestions you might have, since it is still pretty early for this package.

@kohske
Copy link
Author

kohske commented Jun 7, 2012 via email

@ramnathv
Copy link

ramnathv commented Jun 7, 2012

You have two options. Either reinstall the latest developmental version from github, or insert render_html() in your setup chunk. I inadvertently removed it while refactoring the code.

Let me know if it works.

@kohske
Copy link
Author

kohske commented Jun 7, 2012

Thanks. Now it works. Here is the newer version by using the latest version of slidify.
http://kohske.github.com/sandbox/slidify/why-slidify/whyslidify.html#1

And nice post on twitter. I am working on a few things which would allow you to publish your presentation to RPubs in slide format. If folks at RStudio like it, maybe they might consider incorporating it into RStudio so that you can do one-click publishing.

Cool!!! I'm looking forward to it.

@ramnathv
Copy link

ramnathv commented Jun 7, 2012

The google logo should go away with the new version of slidify. I would suggest that you copy your source .Rmd file to a new folder and run slidify. I have made some changes on directory structure (basically organizing external frameworks in a library).

To publish it on github, you would need to set copy_libraries to TRUE. The command to run would be

slidify('whyslidify.Rmd', options = modifyList(slidifyOptions(), list(copy_libraries = TRUE))`

Let me know if this works.

@kohske
Copy link
Author

kohske commented Jun 7, 2012

Yes, I did it. Thanks. Perhaps you see the cache of browser.
Please find the repo directly here: https://github.com/kohske/kohske.github.com/tree/master/sandbox/slidify/why-slidify

@ramnathv
Copy link

ramnathv commented Jun 7, 2012

Excellent. I just realized that I had not pushed the latest version that I was talking to you about. If you reinstall it, you can get rid of the slidify logo as well, since I moved it to a custom css folder that I would use for my slide decks.

@kohske
Copy link
Author

kohske commented Jun 7, 2012

Thanks, updated.
I have one feature request. It would be better if I can manually set the title of the slide page (now "presentation").
If it is not set, the title of the first page may be used for the title of the slide.

@ramnathv
Copy link

ramnathv commented Jun 7, 2012

Can you add this to the issues page so that I don't forget it?

@ramnathv
Copy link

ramnathv commented Jun 7, 2012

I have implemented it so that you can set it manually by using

opts <- modifyList(slidifyOptions(), list(title = 'This is my Title'))
slidify("whyslidify.Rmd", options = opts)

I would still like it if you an add this request to the issues page, so that I remember implementing automatic title detection from the first slide.

@ramnathv
Copy link

@kohske. The latest version of slidify makes uploading slides to rpubs a breeze. If your presentation is named slides.Rmd, just do the following:

opts <- slidifyOptions()
opts$embed = TRUE
slidify('slides.Rmd', options = opts)
rpubsUpload('My Presentation', 'slides.html')

Let me know if it works for you and if you have any suggestions. I could wrap this up in a helper function, but I thought people might want to view the presentation locally before uploading, so kept it separate.

@kohske
Copy link
Author

kohske commented Jun 11, 2012

Hi, thanks.

With the latest version, the slide cannot be correctly generated.
Perhaps the process of headers are broken.

@kohske
Copy link
Author

kohske commented Jun 11, 2012

Great!!
Now I could upload the slide. Thanks.

http://rpubs.com/kohske/318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment