-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
184 lines (138 loc) · 5.28 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
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
#install.packages("shiny")
#install.packages("ggplot")
#install.packages("tidyverse")
library(shiny)
library(ggplot2)
library(tidyverse)
source("RFinalProject_ShutimaP/RFinalProject_ShutimaP.R")
# Define UI for app that draws a histogram ----
ui <- fluidPage(
# App title ----
titlePanel("R for Big Data Final Project: Exploratory Data Analysis of Airbnb Database by Shutima Potivorakun"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Slider for the number of bins ----
sliderInput(inputId = "bins",
label = "Number of bins:",
min = 20,
max = 40,
value = 25),
# Check box for the density estimation
strong("Density Estimation:"),
checkboxInput("checkbox", label = "Enable", value = TRUE),
# Select box for the color
selectInput("select", strong("Color of the Density Function:"),
choices = list("Red" = 1, "Blue" = 2,
"Green" = 3), selected = 1),
# Text for chaning the colors of the scatter plot
textInput("color", strong("Color of the scatter plot points"),
value = "red")
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Histogram ----
plotOutput(outputId = "distPlot"),
# Output: ggplot ----
plotOutput(outputId = "distPlot2"),
# Output: ggplot ----
plotOutput(outputId = "distPlot3"),
# Output: ggplot ----
plotOutput(outputId = "distPlot4"),
# Output: barplot ----
plotOutput(outputId = "distPlot5"),
# Output: ggplot ----
plotOutput(outputId = "distPlot6"),
# Output: ggplot ----
plotOutput(outputId = "distPlot7")
)
)
)
# Define server logic required to draw a histogram ----
server <- function(input, output) {
# Histogram of the Old Faithful Geyser Data ----
# with requested number of bins
# This expression that generates a histogram is wrapped in a call
# to renderPlot to indicate that:
#
# 1. It is "reactive" and therefore should be automatically
# re-executed when inputs (input$bins) change
# 2. Its output type is a plot
output$distPlot <- renderPlot({
#x <- faithful$waiting
#bins <- seq(min(x), max(x), length.out = input$bins + 1)
#hist(x, breaks = bins, col = "#75AADB", border = "white",
# xlab = "Waiting time to next eruption (in mins)",
# main = "Histogram of waiting times", freq = FALSE)
x <- L$price
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = "#75AADB", border = "white",
xlab = "Apartment Price",
main = "Histogram Apartment Price",freq = FALSE)
if (input$checkbox) {
switch(input$select,
"1" = lines(density(x), col = 'red', lwd = 2),
"2" = lines(density(x), col = 'blue', lwd = 2),
"3" = lines(density(x), col = 'green', lwd = 2))
}
})
output$distPlot2 <- renderPlot({
#plot(faithful, type = 'p', pch = 19, col = input$color,
# main = "The faithful data")
p <- L %>%
group_by(neighbourhood) %>%
summarize(price = mean(price)) %>%
ggplot(aes(y = price, x = neighbourhood)) +
geom_col() +
theme(axis.text.x = element_text(size = 8, angle = 90)) +
ggtitle("Average Apt Price per Neighbourhood")
p
})
output$distPlot3 <- renderPlot({
p2 <- tmpRT_new %>%
group_by(Group.1) %>%
summarize(x = mean(x)) %>%
ggplot(aes(y = x, x = Group.1)) +
geom_col() +
theme(axis.text.x = element_text(size = 8, angle = 90)) + ylab("Price") + xlab("Room Type") +
ggtitle("Average Apt Price per Room Type")
p2
})
output$distPlot4 <- renderPlot({
p3 <- tmpBT_new %>%
group_by(Group.1) %>%
summarize(x = mean(x)) %>%
ggplot(aes(y = x, x = Group.1)) +
geom_col() +
theme(axis.text.x = element_text(size = 8, angle = 90)) + ylab("Price") + xlab("Bed Type") +
ggtitle("Average Apt Price per Bed Type")
p3
})
output$distPlot5 <- renderPlot({
count <- table(L$host_total_listings_count)
countHN <- table(L$host_name)
barplot(countHN, count, main = "Number of Apt per owner", xlab = "Host Name", ylab = "Host Total Listings count")
})
output$distPlot6 <- renderPlot({
p4 <- tmpAR_new %>%
group_by(Group.1) %>%
summarize(x = mean(x)) %>%
ggplot(aes(y = x, x = Group.1)) +
geom_col() +
theme(axis.text.x = element_text(size = 8, angle = 90)) + ylab("Price") + xlab("Arrondissement") +
ggtitle("Average Apt Price per Arrondissement")
p4
})
output$distPlot7 <- renderPlot({
p5 <- L %>%
group_by(zipcode) %>%
summarize(reviews_per_month = mean(reviews_per_month)) %>%
ggplot(aes(y = reviews_per_month, x = zipcode)) +
geom_col() +
theme(axis.text.x = element_text(size = 8, angle = 90)) + xlab("Arrondissement") +
ggtitle("Visit Frequency of the Different Quarters according to Time")
p5
})
}
shinyApp(ui = ui, server = server)