Skip to content

Instantly share code, notes, and snippets.

@xgranda
Created October 20, 2019 04:10
Show Gist options
  • Save xgranda/d91b8a622e98490823301cdd934962d4 to your computer and use it in GitHub Desktop.
Save xgranda/d91b8a622e98490823301cdd934962d4 to your computer and use it in GitHub Desktop.
Consumer Analysis of Luxury Hotel's in Europe
------------ui.R---------------
shinyUI(dashboardPage(
dashboardHeader(title = "Europe's Luxury Hotels"),
dashboardSidebar(
sidebarMenu(
menuItem(text = "Home", tabName = "Home",icon = icon("home")),
menuItem(text = "Countries", tabName = "Countries",icon = icon("globe")),
menuItem(text = "Hotels", tabName = "Hotels",icon = icon("concierge-bell")),
menuItem(text = "Reviewers", tabName = "Reviewers",icon = icon("users")),
menuItem(text = "Type of Trip", tabName = "Trip",icon = icon("suitcase-rolling")),
menuItem(text = "Type of Traveller", tabName = "Traveller",icon = icon("smile")),
menuItem(text = "About Me", tabName = "About Me",icon = icon("user"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "Home",
h2("Consumer Analysis of Luxury Hotel's in Europe", align="center"),
h2("Summary:"),
h4("This project shows what type of travelleres
luxury hotels in Europe are receiving in popular cities
such as London, Paris, Amsterdam, Barcelona, etc."),
h2("Objectives:"),
h4("- What reasons motivate people to travel to the different cities and
hotels"),
h4("- How many night's are people spending on the hotel depending the type of trip"),
h4("- Are people travelling by themselves or in groups"),
h4("- Scores they are giving based on their type of trip"),
img(src= 'bedroom-door-entrance-271639.jpg', height=200, width=300, style="display: block; margin-left: auto; margin-right: auto;"),
br(),
h5("The dataset used for this analysis can be found",
a("here", href="https://www.kaggle.com/jiashenliu/515k-hotel-reviews-data-in-europe"))
),
tabItem(tabName = "Countries",
h2("Location of Hotels", align="center"),
leafletOutput("map_1")
),
tabItem(tabName = "Hotels",
fluidRow(valueBoxOutput("max_Hotel_Box", width = 12))
),
tabItem(tabName = "Reviewers",
selectizeInput("Selected",
"Select Nationality",
select_nationality),
fluidRow(valueBoxOutput("max_Reviewer_Box", width = 6),
valueBoxOutput("avg_num_night", width = 6)),
leafletOutput("map_2", height = 350)
),
tabItem(tabName = "Trip",
box(selectizeInput("s_type_trip",
"Select Type of Trip",
trip_list), width = 12),
fluidRow(box(htmlOutput("hotel_score"),width = 6),
box(htmlOutput("pie_trip"),width = 6)
),
box(htmlOutput("bar_night"), width = 12)
),
tabItem(tabName = "Traveller",
box(selectizeInput("t_trip",
"Select Type of Trip",
t_list), width = 12),
box(htmlOutput("traveller_1"), width = 12)
),
tabItem(tabName = "About Me", "About me information here")
),
#Customize title (making it bold and changing it's letter size)
tags$head(tags$style(HTML('
.main-header .logo {
font-weight: bold;
font-size: 18px;
}')))
)
))
------------server.R---------------
shinyServer(function(input, output, session){
#Code for map that will show in Maps tab####
output$map_1= renderLeaflet({
address_filter=test_dataset %>% distinct(Hotel_Address, lat, lng)
leaflet(address_filter) %>%
addTiles() %>%
addMarkers(lng =~lng, lat=~lat,clusterOptions = markerClusterOptions())
})
#Hotel information Tab ####
hotel_1= reactive ({
test_dataset %>%
filter(type_trip==input$h_trip) %>%
group_by(Hotel_Name) %>% tally() %>% top_n(5)
})
output$hotel_trip = renderGvis({
gvisPieChart(hotel_1(), options = list(title="Top 5 Hotels"))
})
output$map_3= renderLeaflet({
hotel_3=head(test_dataset %>%
filter(type_trip=='Leisure trip') %>%
group_by(Hotel_Name, lng, lat) %>%
count(Hotel_Name) %>% arrange(desc(n)),5)
leaflet(hotel_3) %>%
addTiles() %>%
addMarkers(lng =~lng, lat=~lat,clusterOptions = markerClusterOptions())
})
#Type of trip graphs####
output$pie_trip = renderGvis(gvisPieChart(summary_trip,
options = list(title="Percentage of Types of Trips")))
output$bar_night = renderGvis({
night_trip= test_dataset %>%
filter(type_trip==input$s_type_trip) %>%
group_by(Reviewer_Nationality) %>% tally() %>%
rename(Number_of_Bookings=n)%>%
top_n(5)
gvisBarChart(night_trip,
options = list(title= "Top 5 Nationatlities",
titleTextStyle="fontSize = 16",
vAxes="[{title:'Nationalities'}]"))
})
#Graphs for Traveller####
output$traveller_1 = renderGvis({
traveller_type= test_dataset %>%
filter(type_trip==input$t_trip) %>%
group_by(Tags_04) %>% tally()
gvisPieChart(traveller_type,
options = list(title="Types of Travellers"))
})
output$night_1 = renderGvis({
night_type= test_dataset %>%
filter(type_trip==input$t_trip & Tags_04==input$n_trip) %>%
group_by(nights_2) %>% tally()
gvisColumnChart(night_type,
options = list(title="Number of nights"))
})
#Graph for Timeline####
output$time_1 = renderGvis({
timeline= test_dataset %>%
filter(type_trip==input$time_trip & Year==input$time_trip_2) %>%
group_by(Review_Date) %>% tally()
gvisLineChart(timeline)
})
output$time_2 <- renderGvis({
timeline2= test_dataset %>%
filter(type_trip==input$time_trip & Year==input$time_trip_2) %>%
select(Review_Date, Reviewer_Score)
gvisCalendar(timeline2, option=list(width="automatic",
height= 190))
})
#Info box in reviewers tab that shows average review score for each country####
output$max_Reviewer_Box <- renderValueBox({
select_nationality = select_nationality[order(select_nationality$n, decreasing = T),]
avg_score_nationality=test_dataset %>%
filter(Reviewer_Nationality==input$Selected) %>%
summarise(., average=mean(Reviewer_Score))
avg_score_nationality=format(round(avg_score_nationality, 2), nsmall=2)
valueBox(input$Selected,
paste0("Avg. Review Score: ", avg_score_nationality),
icon = icon("star-half-alt"))
})
output$avg_num_night <- renderValueBox({
avg_nights = test_dataset %>%
filter(Reviewer_Nationality==input$Selected) %>%
summarise(., average=mean(nights_2))
avg_nights = format(round(avg_nights, 2), nsmall=2)
valueBox(input$Selected,
paste0("Avg. Number of Nights: ", avg_nights),
icon = icon("bed"))
})
# Most hotels attended by reviewers nationality####
output$map_2= renderLeaflet({
hotel_filter=test_dataset %>%
filter(Reviewer_Nationality==input$Selected) %>%
distinct(Hotel_Address, lat, lng)
leaflet(hotel_filter) %>%
addTiles() %>%
addMarkers(lng =~lng, lat=~lat,clusterOptions = markerClusterOptions())
})
})
------------global.R---------------
library(dplyr)
library(shiny)
library(shinydashboard)
library(ggplot2)
library(DT)
library(splitstackshape)
library(data.table)
library(leaflet)
library(shinythemes)
library(googleVis)
library(rsconnect)
test_dataset = fread("./Hotel_Reviews_newDataset2.csv")
select_nationality = test_dataset %>%
group_by(Reviewer_Nationality) %>%
tally()
summary_trip= test_dataset %>% group_by(type_trip) %>% tally()
summary_trip= summary_trip %>%
filter(!(type_trip=='With a pet'))
trip_list=summary_trip %>% select(type_trip)
traveller = test_dataset%>% group_by(Tags_04) %>% tally()
traveller = traveller %>% select(Tags_04)
test_dataset = test_dataset %>% mutate(., Year=substr(Review_Date,1,4))
test_dataset$Review_Date=as.Date(test_dataset$Review_Date)
years=test_dataset %>% group_by(Year) %>% tally()
years=years %>% select(Year)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment