-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdemo3.Rmd
84 lines (64 loc) · 1.68 KB
/
demo3.Rmd
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
---
title: "Fiji earthquakes"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(crosstalk)
library(dplyr)
quakes$class <- factor(floor(quakes$mag), labels = c("Light", "Moderate", "Strong"))
set.seed(10101)
quakes <- quakes %>% sample_n(200)
sd <- SharedData$new(quakes)
```
Inputs {.sidebar}
-----------------------------------------------------------------------
```{r}
filter_slider("mag", "Magnitude", sd, ~mag, step = 0.1)
filter_slider("depth", "Depth", sd, ~depth)
```
Row 1
-----------------------------------------------------------------------
### Map
```{r}
library(leaflet)
pal <- colorFactor(c("#1f77bf", "#ff7f0e", "#2ca02c"), quakes$class)
leaflet(sd) %>% addTiles() %>% addCircles(
radius = ~mag * 7000, weight = 1, fillOpacity = 0.8,
label = ~as.character(mag), color = ~pal(class)
)
```
### Scatter
```{r}
library(plotly)
plot_ly(sd) %>%
add_markers(x = ~depth, y = ~stations, color = ~class, mode = "markers") %>%
layout(dragmode = "select", showlegend = FALSE)
```
### Histogram
```{r}
library(ggplot2)
renderPlot({
df <- sd$data(withSelection = TRUE, withFilter = TRUE)
ggplot(df, aes(x = mag, fill = selection_factor(df))) +
geom_histogram(binwidth = 0.2) +
scale_fill_selection("#444444", "skyblue1")
}, outputArgs = list(
brush = brushOpts("histBrush", direction = "x"))
)
maintain_selection(sd, "histBrush")
```
Row 2
-----------------------------------------------------------------------
### Table
```{r}
library(DT)
datatable(sd, rownames = FALSE, extensions = 'Scroller', options = list(
scrollY = 200,
scroller = TRUE
))
```