-
Notifications
You must be signed in to change notification settings - Fork 8
/
shiny.Rmd
91 lines (61 loc) · 1.66 KB
/
shiny.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
85
86
87
88
89
90
# Interactive apps with `shiny`
We will need
```{r, message = FALSE}
library("shiny")
```
## The architecture of a `shiny` app
The overview figure below is based and makes reference to
[*the written tutorial*](http://shiny.rstudio.com/tutorial/lesson1/).
![shiny app overview](./figs/shiny-overview.jpg)
### Running the apps
```{r, eval = FALSE}
## in ui.R
shinyUI(fluidPage(...))
```
```{r, eval = FALSE}
## in server.R
shinyServer(function(input, ouput) {
...
})
```
```{r, eval = FALSE}
runApp("app-dir")
```
### Example apps
* [`shiny-app1`](./shiny-app1)
![shiny-app1](./figs/app1.png)
* [`shiny-app2`](./shiny-app1)
![shiny-app2](./figs/app2.png)
### Single-file app
```{r, eval = FALSE}
ui <- fluidPage(...)
server <- function(input, output) { ... }
app <- list(ui = ui, server = server)
runApp(app)
```
### Sharing
* Share the code file(s) and `runApp`
* `runUrl`
* `runGitHub`
* `runGist`
* [shinyapps](http://wwwshinyapps.io)
* Shiny server
### Exercise
Read and understand the code of the apps above and run them
locally. Then, try to update them to replace of add some widgets.
### More interactivity
```{r, eval = FALSE}
plotOutput("pca",
hover = "hover",
click = "click",
dblclick = "dblClick",
brush = brushOpts(
id = "brush",
resetOnNew = TRUE))
```
Example [here](http://shiny.rstudio.com/gallery/plot-interaction-advanced.html).
## Shiny apps
Push your shiny apps online with [shinyapps](http://www.shinyapps.io/).
## References
* [`shiny` page](http://shiny.rstudio.com/)
* [`shiny` cheat sheet](https://www.rstudio.com/wp-content/uploads/2016/01/shiny-cheatsheet.pdf)