├── README.md ├── Project Report.pdf └── ShinyApp.R /README.md: -------------------------------------------------------------------------------- 1 | # Consumer-Behaviour-Analysis-for-Online-Gambling-for-Bwin.com 2 | Project using R and Shiny 3 | -------------------------------------------------------------------------------- /Project Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrineetKaur/Customer-Behaviour-Analysis-Online-Gambling-Website/HEAD/Project Report.pdf -------------------------------------------------------------------------------- /ShinyApp.R: -------------------------------------------------------------------------------- 1 | 2 | if(!require("ggplot2")) install.packages("ggplot2"); library("ggplot2") 3 | if(!require("shiny")) install.packages("shiny"); library("shiny") 4 | if(!require("dplyr")) install.packages("dplyr"); library("dplyr") 5 | if(!require("DT")) install.packages("DT"); library("DT") 6 | if(!require("plotly")) install.packages("plotly"); library("plotly") 7 | if(!require("shinythemes")) install.packages("shinythemes"); library("shinythemes") 8 | if(!require("tidyverse")) install.packages("tidyverse"); library("tidyverse") 9 | if(!require("maptools")) install.packages("maptools"); library("maptools") 10 | if(!require("shinyWidgets")) install.packages("shinyWidgets"); library("shinyWidgets") 11 | if(!require("fBasics")) install.packages("fBasics"); library("fBasics") 12 | if(!require("foreign")) install.packages("foreign"); library("foreign") 13 | if(!require("stringr")) install.packages("stringr"); library("stringr") 14 | if(!require("rsconnect")) install.packages("rsconnect"); library("rsconnect") 15 | #if(!require("devtools")) install.packages("devtools"); library("rsconnect") 16 | #devtools::install_github("rstudio/rsconnect") 17 | 18 | 19 | Datamart<- read.csv("Datamart.csv") 20 | Ggender<-unique(Datamart$Gender) 21 | Ggender<-Ggender[-3] 22 | GApp<-unique(Datamart$ApplicationName) 23 | ui <- fluidPage( 24 | #THEME OF THE PROJECT 25 | theme = shinytheme("superhero"), 26 | #TITLE OF THE PROJECT 27 | titlePanel(titlePanel("Gambling Project :")), 28 | sidebarLayout( 29 | sidebarPanel( 30 | checkboxGroupInput("gender","Select the gender:",Ggender,selected=Ggender), 31 | 32 | pickerInput("Application","Select the applications:",GApp, 33 | multiple = TRUE, 34 | options = list(`actions-box` = TRUE), selected=GApp), 35 | 36 | pickerInput("Country","Select the Country:",GCountry, 37 | multiple = TRUE, 38 | options = list(`actions-box` = TRUE),selected=GCountry) 39 | #Filter Segments 40 | ), 41 | 42 | # Show a plot of the generated distribution 43 | mainPanel( 44 | tabsetPanel(type = "tabs", 45 | id= "tabsetpanel", 46 | 47 | tabPanel(title = "User Information", 48 | splitLayout(plotOutput("Gender_new"),plotOutput("Age_User"))), 49 | 50 | tabPanel(title = "Player Distribution by Language", 51 | plotOutput("language")), 52 | 53 | tabPanel(title = "Player Distribution by Country", 54 | plotOutput("country")), 55 | 56 | tabPanel(title="Player Distribution by Application", 57 | plotOutput("distrib")), 58 | 59 | tabPanel(title = "Analysing Customer Loyalty Trends", 60 | plotOutput("Seg")), 61 | 62 | tabPanel(title="Activation versus Loyalty", 63 | plotOutput("ActivationVsLoyalty")), 64 | 65 | tabPanel(title = "Best Play Days per Product", 66 | splitLayout(cellWidths = c("50%","50%"),plotOutput("poker"),plotOutput("games")),splitLayout(cellWidths = c("50%","50%"),plotOutput("casino"),plotOutput("sports"))), 67 | 68 | tabPanel(title='Best Play Months per Product', 69 | splitLayout(cellWidths = c("50%","50%"),plotOutput("poker1"),plotOutput("games1")),splitLayout(cellWidths = c("50%","50%"),plotOutput("casino1"),plotOutput("sports1"))) 70 | 71 | 72 | 73 | 74 | 75 | ) 76 | ) 77 | ) 78 | ) 79 | server <- function(input, output){ 80 | output$Seg <- renderPlot({ 81 | 82 | data<-Datamart %>% dplyr::filter (!is.na(Segments),Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) 83 | data <- within(data, 84 | Segments <- factor(Segments, 85 | levels=names(sort(table(Segments), 86 | decreasing=TRUE)))) 87 | ggplot(data,aes(x = Segments, fill = Segments)) + 88 | geom_bar() + 89 | scale_fill_manual(values = c("#663300", "#CCCCCC", "#FFFFFF", "#FFCC33"))+ 90 | labs(title = "Segments were derived as per Customer Loyalty", 91 | subtitle = "(Bronze% dplyr::filter (!is.na (Activation_Period), !is.na (Days_Ttl),Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>% select (UserID, Activation_Period, Days_Ttl) 98 | ggplot(data2,aes(x = Days_Ttl, y = Activation_Period))+ 99 | geom_tile() + 100 | xlab("Loyalty (Total no. of Days Played)") + 101 | ylab("Time Delay from Registration and First Payment (Activation Period)") 102 | }) 103 | output$Gender_new<- renderPlot({ 104 | data3 <- Datamart %>% dplyr::filter (Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) 105 | ggplot(data3,aes(x = Gender, fill = Gender)) + 106 | geom_bar() + ggtitle("Gender Distribution For Customers")+ 107 | ylab("Count of Customers")+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 108 | 109 | }) 110 | output$Age_User<- renderPlot({ 111 | data4<- Datamart %>% dplyr::filter(Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) 112 | ggplot(data4,aes(x = Age)) + ggtitle("Age Distribution For Customers")+ 113 | geom_histogram(binwidth = 2,color="white", fill="black") + 114 | ylab("Count of Customers")+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 115 | 116 | }) 117 | output$poker<- renderPlot({ 118 | data5<-Datamart %>% dplyr::filter (Most_Played_Day != 0,Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>% select (UserID, Most_Played_Day) 119 | ggplot(data5,aes(x = Most_Played_Day, fill = Most_Played_Day)) + 120 | geom_bar() + 121 | coord_polar() + 122 | theme_void()+ ggtitle("Poker")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 123 | 124 | }) 125 | 126 | output$games<- renderPlot({ 127 | data6<-Datamart %>% dplyr::filter (Most_Played_Day_Ga != 0,Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>% select (UserID, Most_Played_Day_Ga) 128 | ggplot(data6,aes(x = Most_Played_Day_Ga, fill = Most_Played_Day_Ga)) + 129 | geom_bar() + 130 | coord_polar() + 131 | theme_void()+ ggtitle("Games")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 132 | 133 | }) 134 | output$casino<- renderPlot({ 135 | data7<- Datamart %>%dplyr::filter (Most_Played_Day_Ca != 0,Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>%select (UserID, Most_Played_Day_Ca) 136 | ggplot(data7,aes(x = Most_Played_Day_Ca, fill = Most_Played_Day_Ca)) + 137 | geom_bar() + 138 | coord_polar() + 139 | theme_void()+ ggtitle("Casino")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 140 | 141 | 142 | }) 143 | output$sports<-renderPlot({ 144 | data8<-Datamart %>%dplyr::filter (Most_Played_Day_Sp != 0,Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>%select (UserID, Most_Played_Day_Sp) 145 | ggplot(data8,aes(x = Most_Played_Day_Sp, fill = Most_Played_Day_Sp)) + 146 | geom_bar() + 147 | coord_polar() + 148 | theme_void() + ggtitle("Sports")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 149 | 150 | }) 151 | output$poker1<- renderPlot({ 152 | data9<-Datamart %>% dplyr::filter (Most_Played_Month != 0,Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>% select (UserID, Most_Played_Month) 153 | ggplot(data9,aes(x = Most_Played_Month, fill = Most_Played_Month)) + 154 | geom_bar() + 155 | coord_polar() + 156 | theme_void()+ ggtitle("Poker")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 157 | 158 | }) 159 | 160 | output$games1<- renderPlot({ 161 | data10<-Datamart %>% dplyr::filter (Most_Played_Month_Ga != 0,Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>% select (UserID, Most_Played_Month_Ga) 162 | ggplot(data10,aes(x = Most_Played_Month_Ga, fill = Most_Played_Month_Ga)) + 163 | geom_bar() + 164 | coord_polar() + 165 | theme_void()+ ggtitle("Games")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 166 | 167 | }) 168 | output$casino1<- renderPlot({ 169 | data11<- Datamart %>%dplyr::filter (Most_Played_Month_Ca != 0,Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>%select (UserID, Most_Played_Month_Ca) 170 | ggplot(data11,aes(x = Most_Played_Month_Ca, fill = Most_Played_Month_Ca)) + 171 | geom_bar() + 172 | coord_polar() + 173 | theme_void()+ ggtitle("Casino")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 174 | 175 | 176 | }) 177 | output$sports1<-renderPlot({ 178 | data12<-Datamart %>%dplyr::filter (Most_Played_Month_Sp != 0,Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) %>%select (UserID, Most_Played_Month_Sp) 179 | ggplot(data12,aes(x = Most_Played_Month_Sp, fill = Most_Played_Month_Sp)) + 180 | geom_bar() + 181 | coord_polar() + 182 | theme_void() + ggtitle("Sports")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 183 | 184 | }) 185 | output$language<- renderPlot({ 186 | data12<-Datamart %>%dplyr::filter (LanguageName!="NA",Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) 187 | data13<-within(data12, 188 | LanguageName <- factor(LanguageName, 189 | levels=names(sort(table(LanguageName), 190 | decreasing=TRUE)))) 191 | ggplot(data13,aes(x = LanguageName, fill = LanguageName)) + 192 | geom_bar() + 193 | ylab("Count of Customers") + 194 | theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank()) + ggtitle("Top Languages With Maximum Customers")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 195 | 196 | 197 | 198 | }) 199 | output$country<- renderPlot({ 200 | data14 <-Datamart %>%dplyr::filter (CountryName!="NA",Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) 201 | data15 <- within(data14, 202 | CountryName <- factor(CountryName, 203 | levels=names(sort(table(CountryName), 204 | decreasing=TRUE)))) 205 | data15<-head(data15,8) 206 | ggplot(data15, aes(x = CountryName, fill = CountryName)) + 207 | geom_bar() + 208 | ylab("Count of Customers") + 209 | theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank()) + ggtitle("Top 5 Countries With Maximum Customers")+ theme(plot.title = element_text(hjust = 0.5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 210 | 211 | 212 | }) 213 | output$distrib <- renderPlot({ 214 | data16<-Datamart %>%dplyr::filter (Gender %in% input$gender,ApplicationName%in%input$Application, CountryName%in%input$Country) 215 | data16<-within(data16, 216 | ApplicationName <- factor(ApplicationName, 217 | levels=names(sort(table(ApplicationName), 218 | decreasing=TRUE)))) 219 | ggplot(data16,aes(x = ApplicationName, fill = ApplicationName)) + 220 | geom_bar() + 221 | ylab("Count of Customers") + 222 | theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank())+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black")) 223 | 224 | 225 | 226 | }) 227 | 228 | } 229 | 230 | # Run shny app 231 | shinyApp(ui = ui, server = server) --------------------------------------------------------------------------------