-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
86 lines (73 loc) · 3.03 KB
/
server.R
File metadata and controls
86 lines (73 loc) · 3.03 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
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
library(DT)
library(shiny)
library(googleVis)
shinyServer(function(input, output, session){
observe({
updateYear <- unique(all_vax %>%
filter(., all_vax$vax == input$selectedVax) %>%
.$year)
updateSelectizeInput(
session, "selectedYear",
choices = updateYear,
selected = updateYear[1])
})
globalData <- reactive({
req(input$selectedVax)
req(input$selectedYear)
all_vax %>% filter(., vax == input$selectedVax & year == input$selectedYear)
})
output$bottomData <- renderDataTable({
datatable(globalData() %>% arrange(., vax_rate) %>% head(., 50), rownames=TRUE,
caption = "50 Countries with the Lowest Vaccination Rates")
})
output$map <- renderGvis({
gvisGeoChart(globalData(), locationvar = "Country", colorvar = "vax_rate",
options=list(region="world", displayMode="regions",
resolution="countries", colorAxis = "{colors : ['red', 'green']}",
backgroundColor="lightblue",
keepAspectRatio = TRUE,
width="auto", height="auto"))
})
output$bottom10 <- renderPlot({
bot10 <- globalData() %>% filter(., vax == input$selectedVax & year == input$selectedYear) %>%
arrange(., vax_rate) %>% head(., 10)
ggplot(bot10, aes(x = reorder(Country, vax_rate), y = vax_rate)) +
geom_col(fill = "lightblue") +
ggtitle("10 Countries with the Lowest Vaccination Rates") +
ylab(paste0(input$selectedVax, " Vaccination Rates in ", input$selectedYear)) +
xlab("Countries")
})
output$country <- renderPlot ({
countryData <- reactive({
req(input$selectedCountry)
all_vax %>% filter(., all_vax$Country == input$selectedCountry)
})
ggplot(countryData(), aes(x = year, y = vax_rate, color = vax, group = vax)) +
geom_point()+ geom_line(stat = "identity") +
ggtitle(paste0("Immunization Rate by year for ", input$selectedCountry)) +
xlab("Year") + ylab("Immunization rate (%)") +
scale_x_continuous(breaks=seq(1980,2018,by = 5))},
height = "auto", width = "auto")
output$compare <- renderPlot ({
compareData <- reactive({
req(input$country1)
req(input$country2)
req(input$compareYear)
country_subset <- c(input$country1, input$country2)
all_vax %>% filter(., all_vax$year == input$compareYear & Country %in% country_subset)
})
ggplot(compareData(), aes(x = vax, y = vax_rate, fill = Country, group = Country)) +
geom_histogram(stat = "identity", position = "dodge") +
ggtitle(paste0("Comparing Vaccine Rates Between ", input$country1, " and ", input$country2, " in ", input$compareYear)) +
xlab("Vaccine") +
ylab("Relative Vaccine Rates")
})
output$data <- renderDataTable({
datatable(all_vax, rownames=FALSE)
})
output$overview <- renderUI({
rawText <- readLines('info.txt')
rawText<- paste(rawText, collapse = "")
return(HTML(rawText))
})
})