This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am MarkEdmondson1234 on github. | |
* I am marked (https://keybase.io/marked) on keybase. | |
* I have a public key whose fingerprint is 5D7E 6B62 C8C4 9CAB 9E8C 9004 C15F A69E 22CA F569 | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## in server.r of a shiny app | |
casualImpactData <- reactive({ | |
## only if we have the data ready | |
validate( | |
need(chartData(), "Need data") | |
) | |
data <- chartData() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# secrets.R | |
options( | |
mysql = list( | |
"host" = "YOUR SQL IP", | |
"port" = 3306, | |
"user" = "YOUR SQL USER", | |
"password" = "YOUR USER PW", | |
"databaseName" = "onlinegashiny"), | |
rga = list( | |
"profile_id" = "The GA View ID", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## functions.R | |
library(rga) | |
library(dygraphs) | |
library(zoo) | |
library(tidyr) | |
library(lubridate) | |
library(d3heatmap) | |
library(dplyr) | |
library(stringr) | |
library(DT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(googleAuthR) | |
## change the native googleAuthR scopes to the one needed. | |
options("googleAuthR.scopes.selected" = | |
c("https://www.googleapis.com/auth/urlshortener")) | |
#' Shortens a url using goo.gl | |
#' | |
#' @param url URl to shorten with goo.gl | |
#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## in global.R | |
library(googleAuthR) | |
options("googleAuthR.scopes.selected" = c("https://www.googleapis.com/auth/urlshortener")) | |
shorten_url <- function(url){ | |
body = list( | |
longUrl = url | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("googleAuthR") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(googleAnalyticsR_public) | |
gar_auth(new_user=T) | |
## your profile view Id | |
id <- "XXXXXX" | |
## 61607 results | |
## 30049 unique Ids | |
## 185 Sku's |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## function to get plot data format | |
getCompareTable <- function (test_data, prediction) { | |
require(dplyr) | |
## plot real vs model bought Sku | |
actual_freq <- table(model_data$boughtSku) | |
predicted_freq <- table(prediction) | |
actual_freq <- actual_freq[order(actual_freq)] | |
predicted_freq <- predicted_freq[order(predicted_freq)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Finding number of components | |
pc <- princomp(model_data) | |
plot(pc, type="l") | |
# look for dimension that is ~ 85% variance | |
summary(pc) | |
loadings(pc) | |
# run more convenient pca needed for k-means | |
pc <- prcomp(k_data) |