bookings <- NULL
library(dplyr)
library(shiny)
library(tidyverse)
library(reshape2)
options(shiny.maxRequestSize = 9*1024^2)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
## read in file, filter data, standardize to dollar
bookings_usdollar <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
bookings <- readxl::read_xlsx(file1$datapath)
bookings <- dplyr::filter(bookings,BookingStatus != "Cancelled")
bookings <- dplyr::filter(bookings,Date > "2016-10-29" & Date < "2017-05-31")
bookings <- dplyr::filter(bookings,LocationCode != "CRC")
#change types
bookings$Date <- as.character(bookings$Date)
bookings$ResourceCode <- as.character(bookings$ResourceCode)
bookings$ResourceCode <- as.character(substr(bookings$ResourceCode,1,3))
#bookings$LocationCode <- as.factor(bookings$ResourceCode)
bookings$bookingstatus <- as.factor(bookings$BookingStatus)
bookings$CountryName <- as.factor(bookings$CountryName)
bookings$CityName <- as.factor(bookings$CityName)
bookings$LocationName <- as.factor(bookings$LocationName)
bookings$LocationCode <- as.factor(bookings$LocationCode)
bookings$EndDate <- as.character(bookings$EndDate)
bookings$duration <- bookings$TimeEnd - bookings$TimeStart
bookings$duration <- (as.numeric(bookings$duration)/60)
bookings$ClientRemarks <- as.character(bookings$ClientRemarks)
#bookings$BookedFor <- as.character(bookings$BookedFor)
bookings$ListedPrice <- as.integer(bookings$ListedPrice)
bookings$ActualPrice <- as.integer(bookings$ActualPrice)
bookings$seatNum <- as.numeric(bookings$ResourceCapacity)
bookings$EndDate <- as.Date(bookings$EndDate)
bookings$Date <- as.Date(bookings$Date)
bookings$LocationName <- as.factor(bookings$LocationName)
bookings$Year <- format(bookings$Date,'%Y')
bookings$Year <- as.numeric(bookings$Year)
bookings$location_code <- as.character(substr(bookings$ResourceCode,1,3))
#bookings$TimeStart <- format(bookings$TimeStart,"%H:%M")
#bookings$TimeEnd <- format(bookings$TimeEnd, "%H:%M")
bookings$numDays <- bookings$Date - bookings$EndDate
bookings$hourly_rate <- NULL
##get rid of tests
bookings$test_bool <- FALSE
bookings$test_bool1 <- grepl("test",bookings$BookedFor)
bookings$test_bool2 <- grepl("Test",bookings$BookedFor)
bookings$test_bool3 <- grepl("TEST",bookings$BookedFor)
bookings$test_bool4 <- grepl("test",bookings$ClientRemarks)
bookings$test_bool5 <- grepl("Test",bookings$ClientRemarks)
bookings$test_bool6 <- grepl("TEST",bookings$ClientRemarks)
bookings <- filter(bookings,test_bool1!=TRUE & test_bool2 !=TRUE & test_bool3!=TRUE & test_bool4 !=TRUE & test_bool5!=TRUE & test_bool6 !=TRUE)
######################################
########Standardize Currency##########
######################################
australia_2016 <- filter(bookings, CountryName == "Australia" & Year == 2016)
china_2016 <- filter(bookings, CountryName == "China" & Year == 2016)
hong_kong_2016 <- filter(bookings, CountryName == "Hong Kong" & Year == 2016)
india_2016 <- filter(bookings, CountryName == "India" & Year == 2016)
indonesia_2016 <- filter(bookings, CountryName == "Indonesia" & Year == 2016)
japan_2016 <- filter(bookings, CountryName == "Japan" & Year == 2016)
korea_2016 <- filter(bookings, CountryName == "Korea" & Year == 2016)
macau_2016 <- filter(bookings, CountryName == "Macau" & Year == 2016)
singapore_2016 <- filter(bookings, CountryName == "Singapore" & Year == 2016)
taiwan_2016 <- filter(bookings,CountryName == "Taiwan" & Year == 2016)
australia_2017 <- filter(bookings, CountryName == "Australia" & Year == 2017)
china_2017 <- filter(bookings, CountryName == "China")
hong_kong_2017 <- filter(bookings, CountryName == "Hong Kong" & Year == 2017)
india_2017 <- filter(bookings, CountryName == "India" & Year == 2017)
indonesia_2017 <- filter(bookings, CountryName == "Indonesia" & Year == 2017)
japan_2017 <- filter(bookings, CountryName == "Japan" & Year == 2017)
korea_2017 <- filter(bookings, CountryName == "Korea" & Year == 2017)
macau_2017 <- filter(bookings, CountryName == "Macau" & Year == 2017)
singapore_2017 <- filter(bookings, CountryName == "Singapore" & Year == 2017)
taiwan_2017 <- filter(bookings,CountryName == "Taiwan" & Year == 2017)
australia_2016$ActualPrice <- australia_2016$ActualPrice / 1.35
china_2016$ActualPrice <- china_2016$ActualPrice / 6.91
hong_kong_2016$ActualPrice <- hong_kong_2016$ActualPrice / 7.8
india_2016$ActualPrice <- india_2016$ActualPrice / 67.2
indonesia_2016$ActualPrice <- indonesia_2016$ActualPrice / 13281
singapore_2016$ActualPrice <- singapore_2016$ActualPrice / 1.38
japan_2016$ActualPrice <- japan_2016$ActualPrice / 109
korea_2016$ActualPrice <- korea_2016$ActualPrice / 1155
macau_2016$ActualPrice <- macau_2016$ActualPrice / 7.9
taiwan_2016$ActualPrice <- taiwan_2016$ActualPrice / 32.2
australia_2017$ActualPrice <- australia_2017$ActualPrice / 1.31
china_2017$ActualPrice <- china_2017$ActualPrice / 6.89
hong_kong_2017$ActualPrice <- hong_kong_2017$ActualPrice / 7.8
india_2017$ActualPrice <- india_2017$ActualPrice / 67.2
indonesia_2017$ActualPrice <- indonesia_2017$ActualPrice / 13337.75
singapore_2017$ActualPrice <- singapore_2017$ActualPrice / 1.4075
japan_2017$ActualPrice <- japan_2017$ActualPrice / 112
korea_2017$ActualPrice <- korea_2017$ActualPrice / 1137.125
macau_2017$ActualPrice <- macau_2017$ActualPrice / 7.9
taiwan_2017$ActualPrice <- taiwan_2017$ActualPrice / 30.6
australia_2016$ListedPrice <- australia_2016$ListedPrice / 1.35
china_2016$ListedPrice <- china_2016$ListedPrice / 6.91
hong_kong_2016$ListedPrice <- hong_kong_2016$ListedPrice / 7.8
india_2016$ListedPrice <- india_2016$ListedPrice / 67.2
indonesia_2016$ListedPrice <- indonesia_2016$ListedPrice / 13281
singapore_2016$ListedPrice <- singapore_2016$ListedPrice / 1.38
japan_2016$ListedPrice <- japan_2016$ListedPrice / 109
korea_2016$ListedPrice <- korea_2016$ListedPrice / 1155
macau_2016$ListedPrice <- macau_2016$ListedPrice / 7.9
taiwan_2016$ListedPrice <- taiwan_2016$ListedPrice / 32.2
australia_2017$ListedPrice <- australia_2017$ListedPrice / 1.31
china_2017$ListedPrice <- china_2017$ListedPrice / 6.89
hong_kong_2017$ListedPrice <- hong_kong_2017$ListedPrice / 7.8
india_2017$ListedPrice <- india_2017$ListedPrice / 67.2
indonesia_2017$ListedPrice <- indonesia_2017$ListedPrice / 13337.75
singapore_2017$ListedPrice <- singapore_2017$ListedPrice / 1.4075
japan_2017$ListedPrice <- japan_2017$ListedPrice / 112
korea_2017$ListedPrice <- korea_2017$ListedPrice / 1137.125
macau_2017$ListedPrice <- macau_2017$ListedPrice / 7.9
taiwan_2017$ListedPrice <- taiwan_2017$ListedPrice / 30.6
bookings_usd <- rbind(australia_2016,china_2016,hong_kong_2016,india_2016,indonesia_2016,singapore_2016,japan_2016,korea_2016,macau_2016,taiwan_2016,australia_2017,china_2017,hong_kong_2017,india_2017,indonesia_2017,singapore_2017,japan_2017,korea_2017,macau_2017,taiwan_2017)
##various filters
bookings_usd$meeting_revenue <- bookings_usd$ActualPrice * bookings_usd$duration
bookings_usd$price_per_seat <- bookings_usd$ListedPrice/bookings_usd$seatNum
bookings_usd$Discount <- bookings_usd$ListedPrice - bookings_usd$ActualPrice
bookings_usd <- filter(bookings_usd,duration>0)
bookings_usd <- filter(bookings_usd,meeting_revenue<1000000)
bookings_usd$RoomNum <- as.factor(bookings_usd$ResourceCapacity)
bookings_usd <- bookings_usd[!
is.na(bookings_usd$ActualPrice),]
bookings_usd <- bookings_usd[!
is.na(bookings_usd$price_per_seat),]
bookings_usd <- dplyr::filter(bookings_usd,ListedPrice < 600)
bookings_usd[!
is.na(bookings_usd$ListedPrice),]
})
########Summarized data
categorical_data <- reactive({
if(is.null(bookings_usdollar())){return()}
if(input$category_type == "Display by City")
{
if(is.null(input$cities)){return()}
this_data <- tibble()
for (k in input$cities)
{
current <- bookings_usdollar() %>% filter(CityName==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum==input$seatNum)
}
current <- summarize(group_by(this_data, CityName), avg_hourly_price = mean(ActualPrice),avg_hourly_listed_price=mean(ListedPrice),total_app_revenue = sum(ActualPrice),avg_meeting_revenue = mean(meeting_revenue),avg_duration=mean(duration),avg_capacity = mean(ResourceCapacity))
}
else if(input$category_type == "Display by Country")
{
if(is.null(input$countries)){return()}
this_data <- tibble()
for (k in input$countries)
{
current <- bookings_usdollar() %>% filter(CountryName==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
current <- summarize(group_by(this_data, CountryName), avg_hourly_price = mean(ActualPrice),avg_hourly_listed_price=mean(ListedPrice),total_app_revenue = sum(ActualPrice),avg_meeting_revenue = mean(meeting_revenue),avg_duration=mean(duration),avg_capacity = mean(ResourceCapacity))
}
else if(input$category_type == "Display by Centre")
{
if(is.null(input$centres)){return()}
this_data <- tibble()
for (k in input$centres)
{
current <- bookings_usdollar() %>% filter(location_code==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
current <- summarize(group_by(this_data, LocationName), avg_hourly_price = mean(ActualPrice),avg_hourly_listed_price=mean(ListedPrice),total_app_revenue = sum(meeting_revenue),avg_meeting_revenue = mean(ActualPrice),avg_duration=mean(duration),avg_capacity = mean(ResourceCapacity))
}
current$avg_discount = current$avg_hourly_listed_price - current$avg_hourly_price
current$avg_per_seat = current$avg_hourly_listed_price / current$avg_capacity
current
})
seat_revenue <- reactive({
if(input$category_type == "Display by City")
{
if(is.null(input$cities)){return()}
this_data <- tibble()
for (k in input$cities)
{
current <- bookings_usdollar() %>% filter(CityName==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
seat_summary <- summarize(group_by(this_data, CityName,seatNum),avg_perSeat = mean(price_per_seat),revenue = sum(ActualPrice))
seat_summary$seatNum <- as.factor(seat_summary$seatNum)
}
else if(input$category_type == "Display by Country")
{
if(is.null(input$countries)){return()}
this_data <- tibble()
for (k in input$countries)
{
current <- bookings_usdollar() %>% filter(CountryName==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
seat_summary <- summarize(group_by(this_data, CountryName,seatNum),avg_perSeat = mean(price_per_seat),revenue = sum(ActualPrice))
seat_summary$seatNum <- as.factor(seat_summary$seatNum)
}
else if(input$category_type == "Display by Centre")
{
if(is.null(input$centres)){return()}
this_data <- tibble()
for (k in input$centres)
{
current <- bookings_usdollar() %>% filter(location_code==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
seat_summary <- summarize(group_by(this_data, LocationName,seatNum),avg_perSeat = mean(price_per_seat),revenue = sum(ActualPrice))
seat_summary$seatNum <- as.factor(seat_summary$seatNum)
}
seat_summary
})
hr_price_summary <- reactive({
if(input$category_type == "Display by City")
{
this_data <- tibble()
for (k in input$cities)
{
current <- bookings_usdollar() %>% filter(CityName==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
if(is.null(input$cities))
{
this_data <- bookings_usdollar()
}
}
else if(input$category_type == "Display by Country")
{
this_data <- tibble()
for (k in input$countries)
{
current <- bookings_usdollar() %>% filter(CountryName==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
if(is.null(input$countries))
{
this_data <- bookings_usdollar()
}
}
else if(input$category_type == "Display by Centre")
{
this_data <- tibble()
for (k in input$centres)
{
current <- bookings_usdollar() %>% filter(LocationCode==k)
this_data <- rbind(this_data,current)
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
if(is.null(input$centres))
{
this_data <- bookings_usdollar()
}
}
price_v_hrs <- summarize(group_by(this_data,LocationCode), avg_price = mean(as.numeric(levels(as.factor(ListedPrice)))),total_hrs = sum(duration),seats_sold = sum(ResourceCapacity),avg_capacity = mean(as.numeric(levels(as.factor(ResourceCapacity)))),total_app_revenue = sum(ActualPrice))
price_v_hrs$avg_per_seat <- (price_v_hrs$avg_price / price_v_hrs$avg_capacity)
price_v_hrs
})
var_index <- reactive({
if(input$category_type == "Display by City"){category <- 72}
if(input$category_type == "Display by Country"){category <- 77}
if(input$category_type == "Display by Centre"){category <- 62}
category
})
############# Not summarized
aggregate_data <- reactive({
if(is.null(bookings_usdollar())){return()}
if(input$category_type == "Display by City")
{
this_data <- tibble()
for (k in input$cities)
{
current <- bookings_usdollar() %>% filter(CityName==k)
this_data <- rbind(this_data,current)
}
}
else if(input$category_type == "Display by Country")
{
this_data <- tibble()
for (k in input$countries)
{
current <- bookings_usdollar() %>% filter(CountryName==k)
this_data <- rbind(this_data,current)
}
}
else if(input$category_type == "Display by Centre")
{
this_data <- tibble()
for (k in input$centres)
{
current <- bookings_usdollar() %>% filter(location_code==k)
this_data <- rbind(this_data,current)
}
}
if(input$room_filter)
{
this_data <- filter(this_data,RoomNum == input$seatNum)
}
this_data
})
output$scatterplot <- renderPlot ({
if(is.null(bookings_usdollar())){return()}
ggplot(hr_price_summary(),aes(x=total_hrs,y=avg_per_seat)) + geom_point() + geom_smooth(aes(x=total_hrs,y=avg_per_seat),inherit.aes = FALSE,method = 'lm',se=FALSE) + geom_text(aes(label= LocationCode),nudge_y = 3) + labs(title = "Average Price Per Seat vs Total Hours Booked",x = "Total Hours Booked",y = "Average Price Per Seat")
})
output$second_scatterplot <- renderPlot({
if(is.null(bookings_usdollar())){return}
ggplot(hr_price_summary(),aes(x=seats_sold,y=avg_per_seat)) + geom_point() + geom_smooth(aes(x=seats_sold,y=avg_per_seat),inherit.aes = FALSE,method = 'lm',se=FALSE) + geom_text(aes(label= LocationCode),nudge_y = 3) + labs(title = "Average Price Per Seat vs Total Seats Booked", x = "Total Number of Seats Booked",y = "Average Price Per Seat")
})
# output$myTable <- renderTable({
# seat_revenue()
#})
output$discount_plot <- renderPlot({
if(is.null(categorical_data())){return()}
droppedVars <-names(categorical_data()) %in% c("total_app_revenue","avg_meeting_revenue","avg_meeting_revenue","avg_duration","avg_hourly_listed_price","mean_hourly_pp_price","avg_capacity")
discounts <- categorical_data()[!droppedVars]
discounts <- discounts[c(1,3,2)]
names(discounts)[1] <- "location"
data_melt <- melt(discounts)
hrly_price <- filter(data_melt, variable == "avg_hourly_price")
x_list <- data_melt$location[order(hrly_price$value)]
a <- ggplot(data_melt, aes(x = location, y= value, fill = variable), xlab="Categories") + geom_bar(stat="identity", width=0.6, position = "stack") + scale_y_continuous(name="Dollars") + labs(title = "Average Hourly Discount vs Average Hourly Revenue") + theme(axis.text.x=element_text(angle=90, hjust=1))
a + scale_x_discrete(limits = x_list)
})
output$date_plot <- renderPlot({
if(is.null(aggregate_data())){return()}
if(input$category_type == "Display by Country"){a <- ggplot(aggregate_data(),aes(x=Date,color=CountryName,fill=CountryName)) + geom_density(alpha= 0) + scale_x_date(date_breaks = "1 month") + labs(title = "This is a density or frequency plot of booking dates \n The best interpretation of this is to view it as a probability distribution. \n For Example: click Divide by City and then select Hong Kong. \n Then, open the app data spreadsheet in Excel, \n filter out all the bookings that are not made in Hong Kong \n close your eyes and scroll down the spreadsheet, stopping at a random booking record \n The probability of landing on a booking in mid march (the peak) is a \n little over 1% (0.01 on the Y-Axis). The probability of landing \n on a booking on new years day is a quarter of one percent \n CAUTION: The reason why there are so few bookings toward the far left \n hand of the graph is not because this time of year is unpopular, \n but likely because it took a little while for clients to start \n using the app. This plot starts on November 1st, 2016 which was the day after \n the app went live.")}
if(input$category_type == "Display by City"){a <- ggplot(aggregate_data(),aes(x=Date,color=CityName,fill=CityName)) + geom_density(alpha= 0) + scale_x_date(date_breaks = "1 month") + labs(title = "This is a density or frequency plot of booking dates \n The best interpretation of this is to view it as a probability distribution. \n For Example: click Divide by City and then select Hong Kong. \n Then, open the app data spreadsheet in Excel, \n filter out all the bookings that are not made in Hong Kong \n close your eyes and scroll down the spreadsheet, stopping at a random booking record \n The probability of landing on a booking in mid march (the peak) is a \n little over 1% (0.01 on the Y-Axis). The probability of landing \n on a booking on new years day is a quarter of one percent \n CAUTION: The reason why there are so few bookings toward the far left \n hand of the graph is not because this time of year is unpopular, \n but likely because it took a little while for clients to start \n using the app. This plot starts on November 1st, 2016 which was the day after \n the app went live.") }
if(input$category_type == "Display by Centre"){a <- ggplot(aggregate_data(),aes(x=Date,color=LocationName,fill=LocationName)) + geom_density(alpha= 0) + scale_x_date(date_breaks = "1 month")+ labs(title = "This is a density or frequency plot of booking dates \n The best interpretation of this is to view it as a probability distribution. \n For Example: click Divide by City and then select Hong Kong. \n Then, open the app data spreadsheet in Excel, \n filter out all the bookings that are not made in Hong Kong \n close your eyes and scroll down the spreadsheet, stopping at a random booking record \n The probability of landing on a booking in mid march (the peak) is a \n little over 1% (0.01 on the Y-Axis). The probability of landing \n on a booking on new years day is a quarter of one percent \n CAUTION: The reason why there are so few bookings toward the far left \n hand of the graph is not because this time of year is unpopular, \n but likely because it took a little while for clients to start \n using the app. This plot starts on November 1st, 2016 which was the day after \n the app went live.")}
a
},height = 600)
output$time_plot <- renderPlot({
if(is.null(aggregate_data())){return()}
if(input$category_type == "Display by Country"){b <- ggplot(aggregate_data(),aes(x=TimeStart,color=CountryName,fill=CountryName)) + geom_density(alpha= 0) + scale_x_datetime(breaks = "1 hour") + labs(title = "This plot has exactly the same interpretation as the date plot above \n but it shows the density of meeting start times")} #+ scale_x_datetime(limits =lims, breaks=date_breaks("1 hour"), labels=date_format("%H:%M"))+ theme(axis.text.x=element_text(angle=90))}
if(input$category_type == "Display by City"){b <- ggplot(aggregate_data(),aes(x=TimeStart,color=CityName,fill=CityName)) + geom_density(alpha= 0) + labs(title = "This plot has exactly the same interpretation as the date plot above \n but it shows the density of meeting start times")} #+ scale_x_datetime(limits =lims, breaks=date_breaks("1 hour"), labels=date_format("%H:%M"))+ theme(axis.text.x=element_text(angle=90))}
if(input$category_type == "Display by Centre"){b <- ggplot(aggregate_data(),aes(x=TimeStart,color=LocationName,fill=LocationName)) + geom_density(alpha= 0) + labs(title = "This plot has exactly the same interpretation as the date plot above \n but it shows the density of meeting start times")} #+ scale_x_datetime(limits =lims, breaks=date_breaks("4 hour"), labels=date_format("%H:%M")) + theme(axis.text.x=element_text(angle=90))}
b
})
output$revenue_plot <- renderPlot({
if(is.null(seat_revenue())){return()}
{
if(input$category_type == "Display by Country")
{
f <- ggplot(seat_revenue(), aes(x=CountryName,y=revenue,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Total Revenue From Each Type of Room", y= "Dollars")
}
if(input$category_type == "Display by City")
{
f <- ggplot(seat_revenue(), aes(x=CityName,y=revenue,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Total Revenue From Each Type of Room", y= "Dollars")
}
if(input$category_type == "Display by Centre")
{
f <- ggplot(seat_revenue(), aes(x=LocationName,y=revenue,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Total Revenue From Each Type of Room", y= "Dollars")
}
f
}
})
booking_dates_reactive <- reactive({
if(is.null(bookings_usdollar())){return()}
bookings_small <- bookings_usdollar()["Date"]
bookings_small$day <- weekdays(bookings_small$Date)
booking_dates <- table(bookings_small$Date)
booking_dates <- as.data.frame(booking_dates)
names(booking_dates)[1] <- "Date"
names(booking_dates)[2] <- "BookingCount"
booking_dates$Date <- as.Date(booking_dates$Date)
booking_dates$WeekDay <- weekdays(booking_dates$Date)
booking_dates$WeekDay <- as.factor(booking_dates$WeekDay)
booking_dates
})
output$per_seat_plot <- renderPlot({
if(is.null(seat_revenue())){return()}
{
if(input$category_type == "Display by Country")
{
f <- ggplot(seat_revenue(), aes(x=CountryName,y=avg_perSeat,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Average Hourly Price Per Seat", y= "Dollars")
}
if(input$category_type == "Display by City")
{
f <- ggplot(seat_revenue(), aes(x=CityName,y=avg_perSeat,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Average Hourly Price Per Seat", y= "Dollars")
}
if(input$category_type == "Display by Centre")
{
f <- ggplot(seat_revenue(), aes(x=LocationName,y=avg_perSeat,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Average Hourly Price Per Seat", y= "Dollars")
}
f
}
})
output$roomNumber_plot <- renderPlot({
if(is.null(aggregate_data())){return()}
if(input$category_type == "Display by Country")
{
keepvars <- c("CountryName","RoomNum")
room_nums <- aggregate_data()[keepvars]
names(room_nums)[1] <- "location"
}
else if(input$category_type == "Display by City")
{
keepvars <- c("CityName","RoomNum")
room_nums <- aggregate_data()[keepvars]
names(room_nums)[1] <- "location"
}
else if(input$category_type == "Display by Centre")
{
keepvars <- c("location_code","RoomNum")
room_nums <- aggregate_data()[keepvars]
names(room_nums)[1] <- "location"
}
if(input$category_type == "Display by Country")
{
x_list <- names(sort(table(room_nums$location)))
x_list <- intersect(x_list,input$countries)
c <- ggplot(room_nums, aes(x=location,fill=RoomNum)) + geom_bar(stat="count") + scale_x_discrete(limits = x_list) + labs(title = "Total Number of Meeting Room Bookings",y= "Total Number of Meeting Room Bookings per Country")
}
else if(input$category_type == "Display by City")
{
x_list <- names(sort(table(room_nums$location)))
x_list <- intersect(x_list,input$cities)
c <- ggplot(room_nums, aes(x=location,fill=RoomNum)) + geom_bar(stat="count") + scale_x_discrete(limits = x_list) + scale_x_discrete(limits = x_list) + labs(title = "Total Number of Meeting Room Bookings",y= "Total Number of Meeting Room Bookings per City")
}
else if(input$category_type == "Display by Centre")
{
x_list <- names(sort(table(room_nums$location)))
x_list <- intersect(x_list,input$centres)
c <- ggplot(room_nums, aes(x=location,fill=RoomNum)) + geom_bar(stat="count") + scale_x_discrete(limits = x_list) + labs(title = "Total Number of Meeting Room Bookings",y= "Total Number of Meeting Room Bookings per Centre")
}
c
})
output$day_plot <- renderPlot({
if(is.null(booking_dates_reactive())){return()}
daily_data <- booking_dates_reactive() %>% filter(WeekDay == input$weekday)
g <- ggplot(daily_data) + geom_bar(aes(x=Date,y=BookingCount,color=WeekDay),stat="identity") + scale_y_continuous(limits=(c(0,200)))
g
})
})