forked from nhs-r-community/shiny-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintro_3.Rmd
153 lines (103 loc) · 2.98 KB
/
intro_3.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
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
---
title: "Shiny training- session 3"
author: "Chris Beeley"
output:
ioslides_presentation:
css: temp.css
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
```
## Introduction
Application 3- enhance the A + E one
* RMarkdown
* shinydashboard
* Interacting with a Shiny plot (TBH this is kind of hard)
## RMarkdown
```{r, eval = FALSE}
# UI
downloadButton("downloadReport", "Download report")
# server
output$downloadReport <- downloadHandler(
filename = "report.docx",
content = function(file){
params <- list(date_from = input$date[1],
date_to = input$date[2],
trust = input$trust)
render("report.Rmd", output_format = "word_document",
output_file = "report.docx", quiet = TRUE, params = params,
envir = new.env(parent = globalenv()))
# copy docx to 'file'
file.copy("report.docx", file, overwrite = TRUE)
}
)
```
## In the report
```{r, eval = FALSE}
# YAML
params:
date_from : NA
date_to : NA
trust : NA
# R
load("ae_attendances.RData")
report_data <- ae_attendances %>%
filter(period >= params$date_from, period <= params$date_to,
Name == params$trust)
```
* If they don't select a Trust first they will get an error
* Multiple ways of doing this
* Have a look in the answer sheet to see one after you've had a go yourself
* Helper code in a_and_e_code_fourth.R
* The answer is in the a_and_e_fourth folder. Use sparingly!
## Shiny dashboard
```{r, eval = FALSE}
# this runs and produces a totally blank dashboard
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
server <- function(input, output) { }
shinyApp(ui, server)
```
## Value boxes
```{r, eval = FALSE}
# https://rstudio.github.io/shinydashboard/structure.html#valuebox
# ui
valueBox()
# Dynamic valueBoxes
valueBoxOutput("daysBox")
# server
output$daysBox <- renderValueBox({
valueBox(
)
})
```
* Your turn!
* Open a_and_e_code_fifth.R
* [https://rstudio.github.io/shinydashboard/index.html](https://rstudio.github.io/shinydashboard/index.html)
* Answers in a_and_e_dashboard. Use sparingly
## Deployment
* runGitHub("gapminder", "ChrisBeeley")
* runUrl("http://www.myserver/shinyapps/myshinyapp.zip")
* runGist("6571951")
* Just stick it in a shared area and get people to run it themselves
* shinyapps.io
* ShinyProxy
* Proxied authentication (Apache/ Nginx)
* Paid (RStudio Connect/ Shiny Pro)
* Cloud/ firewalled
## Loading data
* CSV/ .Rdata
* {pins}
* SQL
## Finally
* Add some more value boxes and have a tinker with the rest of the layout of the application
* You could even go back to the layout functions that were in the bonus material for session 2
* Make both plots interactive (hard- answers in a_and_e_interactive)
* Make dynamic value boxes based on interacting with a plot (extreme- no answers)
* You may wish to take one or all of these away as homework