├── README.md ├── server.R └── ui.R /README.md: -------------------------------------------------------------------------------- 1 | web-analytics-dashboard 2 | ======================= 3 | 4 | This is a simple Web Analytics Dashboard created with R and Shiny package. Visualizations are interactive and make use of Google Charts. 5 | 6 | The App is composed by twi files: 7 | - server.R 8 | - ui.R 9 | 10 | Data have been downloaded from Google Analytics, though you can also set up an API connection via RGoogleAnalytics package in R. 11 | 12 | You can also check out an explanatory post how I made this app at this link: http://www.analyticsforfun.com/2015/01/google-analytics-dashboards-with-r-shiny.html 13 | -------------------------------------------------------------------------------- /server.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(googleVis) 3 | library(devtools) 4 | 5 | # Source my datasets .csv from Google Analytics) 6 | 7 | visits<-read.csv("visits-bounce-conv-LastMonth.csv") 8 | channels<-read.csv("channels-LastMonth.csv") 9 | countries<- read.csv("newusers-country-LastMonth.csv") 10 | 11 | # CLEANING 12 | 13 | # Clean dataset 1 14 | head(visits) 15 | #visits<-head(visits,-1) 16 | colnames(visits)<- tolower(colnames(visits)) 17 | str(visits) 18 | colnames(visits)<- c("date", "device","sessions","bounce.rate","signup") 19 | visits$bounce.rate <- gsub("%","",visits$bounce.rate) 20 | visits$sessions <- gsub(",","",visits$sessions) 21 | visits$bounce.rate <- as.numeric(visits$bounce.rate) 22 | visits$sessions <- as.numeric(visits$sessions) 23 | visits$signup <- as.numeric(visits$signup) 24 | head(visits) 25 | 26 | # Clean Dataset 2 27 | head(channels) 28 | colnames(channels)<- tolower(colnames(channels)) 29 | colnames(channels)<- c("channel", "device","sessions","new.users","bounce.rate","pages.sessions","avg.session.duration","revenue") 30 | ### START BACK FROM HERE 31 | channels$sessions <- gsub(",","",channels$sessions) 32 | channels$sessions <- as.numeric(as.character(channels$sessions)) 33 | 34 | # Clean dataset 3 35 | head(countries) 36 | colnames(countries)<- tolower(colnames(countries)) 37 | colnames(countries)<- c("device", "country","sessions","new.sessions","new.users","bounce.rate","pages/sessions","avg.session.duration") 38 | countries$new.users <- gsub(",","",countries$new.users) 39 | countries$new.users <- as.numeric(as.character(countries$new.users)) 40 | 41 | 42 | # Define server logic 43 | shinyServer(function(input,output){ 44 | 45 | output$dashboard<- renderGvis({ 46 | 47 | # Make a Line Chart with primary axis for Sessions and secondary axis for Signups 48 | dataDevice<- subset(visits, device==input$radio) 49 | Line2axis <- gvisLineChart(dataDevice, "date", c("sessions","signup"), 50 | options=list( 51 | series="[{targetAxisIndex: 0}, 52 | {targetAxisIndex:1}]", 53 | vAxes="[{title:'Sessions'}, {title:'Signups'}]", 54 | title="Visits & Sign-up Trend Last Month", 55 | width=500, height=300 56 | )) 57 | 58 | # Make a Bubble Chart to see Channels Performance 59 | channelsDevice<- subset(channels, device==input$radio) 60 | Bubble <- gvisBubbleChart(channelsDevice, idvar="channel", 61 | xvar="sessions", yvar="pages.sessions", 62 | colorvar="channel", sizevar="revenue", 63 | options=list( 64 | title="Channels Performance (Revenue = Size of the Bubble)", 65 | vAxis="{title: 'Pages per Session'}", 66 | hAxis="{title: 'Sessions'}", 67 | width=500, height=300, 68 | legend = 'none')) 69 | 70 | #Merge first two charts horizontally 71 | D12 <- gvisMerge(Line2axis,Bubble, horizontal=TRUE) 72 | 73 | 74 | # Line chart to plot Bounce Rate evolution 75 | #dataDevice<- subset(visits, device==input$radio) 76 | Bounce<- gvisLineChart(dataDevice, xvar="date", yvar="bounce.rate", 77 | options = list(title="Bounce Rate Trend Last Month", 78 | vAxis="{title: 'Bounce Rate %'}", 79 | width=500, height=300, 80 | legend = 'none')) 81 | 82 | # Map chart to analyse new users by country 83 | countriesDevice<- subset(countries, device==input$radio) 84 | C <- gvisGeoChart(countriesDevice, "country", "new.users", 85 | options = list(title="New Users by Country", 86 | width=500, height=300, 87 | legend = 'none')) 88 | 89 | #Merge the other two charts horizontally 90 | D34 <- gvisMerge(Bounce,C, horizontal=TRUE) 91 | #Merge two pairs of charts vertically 92 | D1234<- gvisMerge(D12,D34, horizontal=FALSE) 93 | 94 | #Plot entire Dashboard 95 | D1234 96 | 97 | }) 98 | 99 | }) 100 | -------------------------------------------------------------------------------- /ui.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | 3 | 4 | # Define UI for my application 5 | shinyUI(pageWithSidebar( 6 | 7 | # my Application title 8 | headerPanel("Web Analytics Dashboard with R Shiny"), 9 | 10 | # a sidebar with radio buttons to choose specific segments of web traffic 11 | 12 | sidebarPanel( 13 | 14 | 15 | radioButtons("radio", label="Segment Web Traffic by Device:", 16 | choices=list("Desktop" = "desktop", 17 | "Mobile" = "mobile", 18 | "Tablet" = "tablet"),selected="mobile"), 19 | 20 | #Shiny app Documentation 21 | br(), 22 | 23 | helpText(p(("This Shiny app simulates a Web Analytics Dashboard. The objective of 24 | a dashboard is to display the"),strong("current status of key web metrics"), 25 | ("and arrange it on a single view so the information can be monitored 26 | at a glance.")), 27 | 28 | p("By clicking on radio buttons, you can decide to segment data 29 | by a particular traffic device (desktop, mobile or tablet) 30 | and spot differences in performance."), 31 | 32 | p(strong("Charts are interactive!"),(" Hover your mouse over them to see more 33 | details.")), 34 | 35 | p("Source of data: Google Analytics (web property is confidential)."), 36 | 37 | p("Timeframe: November 2014")), 38 | 39 | width= 3 40 | ), 41 | 42 | mainPanel( 43 | 44 | htmlOutput("dashboard") 45 | 46 | ) 47 | 48 | )) 49 | --------------------------------------------------------------------------------