-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathshiny.Rmd
More file actions
58 lines (47 loc) · 1.13 KB
/
shiny.Rmd
File metadata and controls
58 lines (47 loc) · 1.13 KB
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
---
title: "ggplot2 Brushing"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: menu
source_code: embed
runtime: shiny
---
```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(datasets)
mtcars2 <- mtcars[, c("mpg", "cyl", "wt")]
```
```{r}
# Reactive that returns the whole dataset if there is no brush
selectedData <- reactive({
data <- brushedPoints(mtcars2, input$plot1_brush)
if (nrow(data) == 0)
data <- mtcars2
data
})
```
Column {data-width=650}
-----------------------------------------------------------------------
### Miles Per Gallon vs. Weight {data-width=600}
```{r}
library(ggplot2)
plotOutput("plot1", brush = brushOpts(id = "plot1_brush"))
output$plot1 <- renderPlot({
ggplot(mtcars2, aes(wt, mpg)) + geom_point()
})
```
### Miles Per Gallon and Cylinders
```{r}
renderPlot({
ggplot(selectedData(), aes(factor(cyl), mpg)) + geom_boxplot()
})
```
Column {data-width=350}
-----------------------------------------------------------------------
### Car Details {data-width=400}
```{r}
renderTable({
selectedData()
})
```