forked from lindsaypoirier/Data-Ethnographies-Lab-Book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab9.Rmd
339 lines (282 loc) · 16 KB
/
lab9.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
---
title: "Lab 9 - Presenting Data"
output:
html_notebook:
toc: yes
toc_depth: 3
toc_float: yes
html_document:
df_print: paged
toc: yes
toc_depth: '3'
editor_options:
chunk_output_type: inline
---
## Instructions and Overview
This week, I'd like you to primarily focus on preparing your final presentation. However, we will also spend just a bit of time documenting the uncertainty in each of the numbers and plots on our dashboards.
## Getting Started
### Load the relevant libraries
```{r}
library(tidyverse)
library(lubridate)
library(shiny)
library(shinydashboard)
library(shinyWidgets)
```
### Import and clean example datasets
```{r}
hospitals <- read.csv("https://raw.githubusercontent.com/lindsaypoirier/STS-115/master/datasets/Hospitals.csv", stringsAsFactors = FALSE)
cases <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv", stringsAsFactors = FALSE)
#Do not worry about this line of code for now. Since the cases data gets appended every day with a new column representing that day's case counts, if we want the total cases per country, we need to add up all of the previous day's counts into a new column. The column below does this for us.
cases <-
cases %>%
mutate(Total.Cases =
cases %>%
select(starts_with("X")) %>%
rowSums()
) %>%
select(Province.State, Country.Region, Total.Cases)
hospitals$ZIP <- as.character(hospitals$ZIP)
hospitals$ZIP <- str_pad(hospitals$ZIP, 5, pad = "0")
is.na(hospitals) <- hospitals == "NOT AVAILABLE"
is.na(hospitals) <- hospitals == -999
is.na(cases) <- cases == ""
hospitals$SOURCEDATE <- ymd_hms(hospitals$SOURCEDATE)
hospitals$VAL_DATE <- ymd_hms(hospitals$VAL_DATE)
```
### Import and clean your dataset
```{r}
#Copy and paste relevant code from Lab 4 to import your data here.
#Copy and paste relevant code from Lab 4 to clean your data here. This includes any row binding, character removals, converions in variable type, date formatting, or NA conversions.
```
## Continue your shiny app
At this point, we are going to add text to the front interface of our Shiny app considering the issues that are not addressed in each of our calculations or plots. Follow the instructions below to fill your text into comment boxes on the front page of the app.
We won't be touching the input variables this week. First copy and paste your input variables from lab 7.
```{r}
#======================
#COPY AND PASTE THE INPUT VARIABLES SECTION FROM LAB 7 BELOW
#======================
geo_input_choices <-
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE STATE BELOW WITH YOUR OWN GEOGRAPHIC VARIABLE
select(STATE) %>%
distinct() %>%
#REPLACE STATE BELOW WITH YOUR OWN GEOGRAPHIC VARIABLE
arrange(STATE)
#COMMENT LINES BELOW IF YOU DO NOT HAVE A TEMPORAL VARIABLE IN YOUR DATAFRAME
date_input_start <-
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE SOURCEDATE BELOW WITH YOUR OWN TEMPORAL VARIABLE
summarize(date = min(SOURCEDATE))
date_input_end <-
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE SOURCEDATE BELOW WITH YOUR OWN TEMPORAL VARIABLE
summarize(date = max(SOURCEDATE))
#COMMENT LINES ABOVE IF YOU DO NOT HAVE A TEMPORAL VARIABLE IN YOUR DATAFRAME
#======================
#COPY AND PASTE THE INPUT VARIABLES SECTION FROM LAB 7 ABOVE
#======================
```
In the UI function below, you are going to complete the 7 statements following the commented instruction "#COMPLETE THE STATEMENT BELOW FOR..." Once you've completed these statements, copy and paste the rest of the UI function from lab 8 where I've indicated.
```{r}
ui <- dashboardPage(
#REPLACE 'TITLE HERE' BELOW WITH YOUR OWN TITLE
dashboardHeader(title = "TITLE HERE"),
#REPLACE 'TITLE HERE' ABOVE WITH YOUR OWN TITLE
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("About the Data", tabName = "about", icon = icon("info-sign"))
),
selectInput(inputId = "geo_val", label = "Select an geography:", choices = geo_input_choices, selected = geo_input_choices[1]),
#COMMENT LINE BELOW IF YOU DO NOT HAVE A TEMPORAL VARIABLE IN YOUR DATAFRAME
dateRangeInput(inputId = "date_val", label = "Select a date range:", start = date_input_start$date, end = date_input_end$date)
#COMMENT LINE ABOVE IF YOU DO NOT HAVE A TEMPORAL VARIABLE IN YOUR DATAFRAME
),
dashboardBody(
tags$head(tags$style(HTML('.content-wrapper { overflow: auto; }'))),
tabItems(
tabItem(tabName = "dashboard",
infoBoxOutput("value1", width = 4),
infoBoxOutput("value2", width = 4),
infoBoxOutput("value3", width = 4),
#COMPLETE THE STATEMENT BELOW FOR VALUEBOX 1
box(tags$p("The number above does not account for..."), width = 4),
#COMPLETE THE STATEMENT BELOW FOR VALUEBOX 2
box(tags$p("The number above does not account for..."), width = 4),
#COMPLETE THE STATEMENT BELOW FOR VALUEBOX 3
box(tags$p("The number above does not account for git, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam ei"), width = 4),
box(plotOutput("plot1")),
box(plotOutput("plot2")),
#COMPLETE THE STATEMENT BELOW FOR PLOT 1
box(tags$p("The plot above does not account for..."), width = 6),
#COMPLETE THE STATEMENT BELOW FOR PLOT 2
box(tags$p("The plot above does not account for..."), width = 6),
box(plotOutput("plot3")),
box(plotOutput("plot4")),
#COMPLETE THE STATEMENT BELOW FOR PLOT 3
box(tags$p("The plot above does not account for..."), width = 6),
#COMPLETE THE STATEMENT BELOW FOR PLOT 4
box(tags$p("The plot above does not account for..."), width = 6)
),
#======================
#COPY AND PASTE THE REMAINDER OF THE UI FUNCTION FROM LAB 8 BELOW
#======================
tabItem(tabName = "about",
tags$h1("Data Source"),
#REPLACE TEXT IN QUOTATIONS BELOW WITH YOUR OWN TEXT ABOUT YOUR DATA'S SOURCE
tags$p("Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"),
#REPLACE TEXT IN QUOTATIONS ABOVE WITH YOUR OWN TEXT ABOUT YOUR DATA'S SOURCE
tags$h1("Data Context"),
#REPLACE TEXT IN QUOTATIONS BELOW WITH YOUR OWN TEXT ABOUT YOUR DATA'S CONTEXT
tags$p("Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"),
#REPLACE TEXT IN QUOTATIONS ABOVE WITH YOUR OWN TEXT ABOUT YOUR DATA'S SOURCE
tags$h1("Insights"),
#REPLACE TEXT IN QUOTATIONS BELOW WITH YOUR OWN TEXT ABOUT YOUR INSIGHTS
tags$p("Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"),
#REPLACE TEXT IN QUOTATIONS ABOVE WITH YOUR OWN TEXT ABOUT YOUR INSIGHTS
tags$h1("Knowledge Gaps"),
#REPLACE TEXT IN QUOTATIONS BELOW WITH YOUR OWN TEXT ABOUT YOUR KNOWLEDGE GAPS
tags$p("Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?")
#REPLACE TEXT IN QUOTATIONS ABOVE WITH YOUR OWN TEXT ABOUT YOUR KNOWLEDGE GAPS
)
)
)
)
#======================
#COPY AND PASTE THE REMAINDER OF THE UI FUNCTION FROM LAB 8 ABOVE
#======================
```
We won't be touching the server function this week. You can copy and paste yours from Lab 7 to replace my code below.
```{r}
#======================
#COPY AND PASTE THE SERVER FUNCTION FROM LAB 7 BELOW
#======================
server <- function(input, output) {
output$value1 <- renderInfoBox({
quant_insight1 <-
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE STATE WITH YOUR OWN GEOGRAPHIC VARIABLE AND SOURCEDATE WITH YOUR OWN TEMPORAL VARIABLE
filter(
STATE == input$geo_val &
SOURCEDATE > input$date_val[1] &
SOURCEDATE < input$date_val[2]
) %>%
#COPY AND PASTE YOUR FUNCTION HERE FROM LAB 6
filter(STATUS == "OPEN" & TYPE == "GENERAL ACUTE CARE") %>%
summarize(median_value = median(BEDS, na.rm = TRUE))
#REPLACE 'FILL DESCRIPTION HERE' BELOW WITH YOUR OWN DESCRIPTION
infoBox(quant_insight1,'FILL DESCRIPTION HERE', icon = icon("stats", lib='glyphicon'), color = "purple")
})
output$value2 <- renderInfoBox({
quant_insight2 <-
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE STATE WITH YOUR OWN GEOGRAPHIC VARIABLE AND SOURCEDATE WITH YOUR OWN TEMPORAL VARIABLE
filter(
STATE == input$geo_val &
SOURCEDATE > input$date_val[1] &
SOURCEDATE < input$date_val[2]
) %>%
#COPY AND PASTE YOUR FUNCTION HERE FROM LAB 6
filter(STATUS == "OPEN" & TYPE == "GENERAL ACUTE CARE") %>%
summarize(median_value = median(BEDS, na.rm = TRUE))
#REPLACE 'FILL DESCRIPTION HERE' BELOW WITH YOUR OWN DESCRIPTION
infoBox(quant_insight2,'FILL DESCRIPTION HERE', icon = icon("stats", lib='glyphicon'), color = "purple")
})
output$value3 <- renderInfoBox({
quant_insight3 <-
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE STATE WITH YOUR OWN GEOGRAPHIC VARIABLE AND SOURCEDATE WITH YOUR OWN TEMPORAL VARIABLE
filter(
STATE == input$geo_val &
SOURCEDATE > input$date_val[1] &
SOURCEDATE < input$date_val[2]
) %>%
#COPY AND PASTE YOUR FUNCTION HERE FROM LAB 6
filter(STATUS == "OPEN" & TYPE == "GENERAL ACUTE CARE") %>%
summarize(median_value = median(BEDS, na.rm = TRUE))
#REPLACE 'FILL DESCRIPTION HERE' BELOW WITH YOUR OWN DESCRIPTION
infoBox(quant_insight3,'FILL DESCRIPTION HERE', icon = icon("stats", lib='glyphicon'), color = "purple")
})
output$plot1 <- renderPlot({
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE STATE WITH YOUR OWN GEOGRAPHIC VARIABLE AND SOURCEDATE WITH YOUR OWN TEMPORAL VARIABLE
filter(
STATE == input$geo_val &
SOURCEDATE > input$date_val[1] &
SOURCEDATE < input$date_val[2]
) %>%
#COPY AND PASTE YOUR PLOT HERE FROM LAB 6
filter(STATUS == "OPEN") %>%
ggplot(aes(x = TYPE)) +
geom_bar() +
labs(title = "Number of Hospitals in the US that are Open by Type", x = "Type", y = "Count of Hospitals") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust=1))
})
output$plot2 <- renderPlot({
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE STATE WITH YOUR OWN GEOGRAPHIC VARIABLE AND SOURCEDATE WITH YOUR OWN TEMPORAL VARIABLE
filter(
STATE == input$geo_val &
SOURCEDATE > input$date_val[1] &
SOURCEDATE < input$date_val[2]
) %>%
#COPY AND PASTE YOUR PLOT HERE FROM LAB 6
filter(STATUS == "OPEN") %>%
ggplot(aes(x = TYPE)) +
geom_bar() +
labs(title = "Number of Hospitals in the US that are Open by Type", x = "Type", y = "Count of Hospitals") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust=1))
})
output$plot3 <- renderPlot({
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE STATE WITH YOUR OWN GEOGRAPHIC VARIABLE AND SOURCEDATE WITH YOUR OWN TEMPORAL VARIABLE
filter(
STATE == input$geo_val &
SOURCEDATE > input$date_val[1] &
SOURCEDATE < input$date_val[2]
) %>%
#COPY AND PASTE YOUR PLOT HERE FROM LAB 6
filter(STATUS == "OPEN") %>%
ggplot(aes(x = TYPE)) +
geom_bar() +
labs(title = "Number of Hospitals in the US that are Open by Type", x = "Type", y = "Count of Hospitals") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust=1))
})
output$plot4 <- renderPlot({
#REPLACE hospitals BELOW WITH YOUR OWN DATAFRAME
hospitals %>%
#REPLACE STATE WITH YOUR OWN GEOGRAPHIC VARIABLE AND SOURCEDATE WITH YOUR OWN TEMPORAL VARIABLE
filter(
STATE == input$geo_val &
SOURCEDATE > input$date_val[1] &
SOURCEDATE < input$date_val[2]
) %>%
#COPY AND PASTE YOUR PLOT HERE FROM LAB 6
filter(STATUS == "OPEN") %>%
ggplot(aes(x = TYPE)) +
geom_bar() +
labs(title = "Number of Hospitals in the US that are Open by Type", x = "Type", y = "Count of Hospitals") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust=1))
})
}
#======================
#COPY AND PASTE THE SERVER FUNCTION FROM LAB 7 ABOVE
#======================
```
```{r}
shinyApp(ui, server)
```