-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
133 lines (100 loc) · 3.59 KB
/
app.R
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
ui <- navbarPage(
title = "Happiness", id = "main",
tabPanel(title = "Maps", leafletOutput(outputId = "bbmap", height = "1220"),
absolutePanel(top = 75, right = 20,
pickerInput(inputId = "year", label = "Select a Year",
choices = list("2015", "2016", "2017"),
options = list(`live-search` = TRUE),
multiple = FALSE))),
tabPanel(title = "Analysis",
sidebarPanel(
width = 2,
pickerInput(inputId = "ayear", label = "Select a Year",
choices = list("2015", "2016", "2017"),
options = list(`live-search` = TRUE),
multiple = FALSE),
),
mainPanel(
column(4, plotOutput("CorrPlots", width = "500px", height = "400px")),
column(4, plotOutput("HappyCont", width = "550px", height = "400px")),
column(1, plotOutput("PredPlot", width = "400px", height = "400px")),
)
),
tabPanel("Data", DT::dataTableOutput("data"))
)
server <- function(input, output, session) {
correctData <- reactive({
if (input$year == "2015") {
New_2015
}
else if (input$year == "2016") {
New_2016
}
else {
New_2017
}
})
corrData <- reactive({
if (input$ayear == "2015") {
CorData15
}
else if (input$ayear == "2016") {
CorData16
}
else {
CorData17
}
})
barData <- reactive({
if (input$ayear == "2015") {
MeltedAggr15
}
else if (input$ayear == "2016") {
MeltedAggr16
}
else {
MeltedAggr17
}
})
predData <- reactive({
if (input$ayear == "2015") {
actual15
}
else if (input$ayear == "2016") {
actual16
}
else {
actual17
}
})
New_2015$popupText
output$bbmap <- renderLeaflet({
leaflet(correctData()) %>% addTiles() %>%
addMarkers(lng = ~Longitude, lat = ~Latitude, popup = ~popupText)
})
observe({
leafletProxy("bbmap", data = correctData()) %>% clearShapes() %>%
addMarkers(lng = ~Longitude, lat = ~Latitude, popup = ~popupText)
})
output$data <- DT::renderDataTable(datatable(
correctData(), filter = 'top', colnames = colnames(correctData())
))
output$CorrPlots <- renderPlot({
corrplot(corrData(), method = "number")
})
output$HappyCont <- renderPlot({
ggplot(data = barData(), aes(y = Value, x = Continent, color = Continent, fill = Continent)) +
geom_bar(stat = "identity") + facet_wrap(~Variable) + theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = "Average value of happiness variables for different continents", y = "Average value")
})
output$PredPlot <- renderPlot({
ggplot(predData(), aes(Actual, Prediction)) +
geom_point() + theme_bw() + geom_abline() +
labs(title = "Multiple Linear Regression",
x = "Actual happiness score", y = "Predicted happiness score") +
theme(plot.title = element_text(family = "Helvetica", face = "bold", size = (15)),
axis.title = element_text(family = "Helvetica", size = (10)))
})
}
runApp(shinyApp(ui, server), launch.browser = TRUE)