worksheet-7.Rmd 2.8 KB
Newer Older
Zheng Liu's avatar
rmd  
Zheng Liu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
---
output: ioslides_presentation
#html_document
# ioslides_presentation
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
library(knitr)
library(tools)
opts_chunk$set(
  message = FALSE,
  warning = FALSE,
  cache = TRUE)
```

## Seeing is Believing

```{r}
x <- rnorm(10)
mean(x)
```

Plain text about *something* important.

Bulleted Lists

- SQL
- Python
- R

Numbered Lists

4. SQL
1. Python
12. R

Tables

id | treatment
---|-----
1  | control
2  | exclosure

# The Biggest Heading

## The Second Heading

### The Third Biggest Heading

#### Another
##### Another
## Chunks

```
The *emphasis* indicated by asterisks here does not become
italicized, as it would outside the "code fence".
```

```
seq(1,10)
```

## RMarkdown

```{r}
seq(1, 10)
```

## Chunk Options

```{r does_not_run, eval = FALSE}
seq(1, 10)
```

## Chunk Labels

```{...}
seq(1, 10)
```

## Sourced Input

```{r load_data,context = 'data', echo = FALSE,cache.extra = md5sum('worksheet-7.R')}
source('worksheet-7.R')
cty_to_cty <- subset(cty_to_cty, !is.na(movers_state_est))
```

```{r bar_plot, echo = FALSE}
library(ggplot2)
ggplot(state_movers,
  aes(x = reorder(current_state,-sum_new_movers), y = sum_new_movers)) +
  geom_bar(stat = 'identity') +
  theme(axis.text.x = element_text(
    angle = 90, hjust = 1))
```

## Alternative Engines

```{}
greeting = 'Hello, {}!'
print(greeting.format('World'))
```

```{bash}
echo "Hello, ${USER}!"
```

## Cache Dependencies

```{r clean_bar_plot, dependson='load_data', echo = FALSE}
ggplot(state_movers,
  aes(
    x = reorder(current_state, -sum_new_movers), 
    y = sum_new_movers)) +
  geom_bar(stat = 'identity') +
  theme(axis.text.x = element_text(
    angle = 90, hjust = 1))
```

## Input Objects

```{r, echo = FALSE}
selectInput('pick_state',
  label = 'Pick a State',
  choices = unique(cty_to_cty[['current_state']]))
```

```{r, context = 'server'}
library(dplyr)
output [['mov_plot']] <- renderPlot({
cty_to_cty %>%
    filter(current_state == input[['pick_state']]) %>%
    group_by(prior_1year_state) %>%
    summarise(sum_new_movers = sum(movers_state_est, na.rm = TRUE)) %>%
    ggplot(aes(x = prior_1year_state, y = sum_new_movers)) +
    geom_bar(stat = 'identity') +
    theme(axis.text.x = element_text(angle = 90, hjust = 1))
})
```

```{r, echo = FALSE}
plotOutput('mov_plot')
```

## Reactivity

```{r, context = 'server'}
plot_data <- reactive({
  filter(cty_to_cty, current_state == input[['pick_state']]) %>%
    group_by(prior_1year_state) %>%
    summarise(sum_new_movers = sum(movers_state_est, na.rm = TRUE))
})
output[['react_mov_plot']] <- renderPlot({
  plot_data() %>%
  ggplot(aes(x = prior_1year_state, y = sum_new_movers)) +
       geom_bar(stat = 'identity') +
       theme(axis.text.x = element_text(angle = 90, hjust = 1))
})
```

```{r, echo = FALSE}
plotOutput('react_mov_plot')
```