Skip to content

Instantly share code, notes, and snippets.

View MarkEdmondson1234's full-sized avatar
🦑
Tappity tap tap

Mark Edmondson MarkEdmondson1234

🦑
Tappity tap tap
View GitHub Profile
install.packages("googleAuthR")
@MarkEdmondson1234
MarkEdmondson1234 / shiny_url_short.R
Created August 19, 2015 07:47
Demo using Shiny with googleAuthR
## in global.R
library(googleAuthR)
options("googleAuthR.scopes.selected" = c("https://www.googleapis.com/auth/urlshortener"))
shorten_url <- function(url){
body = list(
longUrl = url
)
@MarkEdmondson1234
MarkEdmondson1234 / url_short.R
Last active August 29, 2015 14:27
Demo using googleAuthR to create a Google API package
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
#'
@MarkEdmondson1234
MarkEdmondson1234 / combineCSVfiles.R
Created August 10, 2015 08:04
combine all csv files in a folder
## assuming you have a folder full of .csv's to merge
## csv's must all have identical column names.
folder <- "./path/to/csv/files"
filenames <- list.files(folder)
all_files <- Reduce(rbind, lapply(filenames, read.csv))
@MarkEdmondson1234
MarkEdmondson1234 / downloadSearchAnalytics.R
Last active March 2, 2016 13:49
demo on how to download and archive search analytics data using searchConsoleR
## A script to download and archive Google search analytics
##
## Demo of searchConsoleR R package.
##
## Version 1 - 10th August 2015
##
## Mark Edmondson (http://markedmondson.me)
## load the required libraries
## (Download them with install.packages("googleAuthR") and install.packages("searchConsoleR" if necessary
## functions.R
library(rga)
library(dygraphs)
library(zoo)
library(tidyr)
library(lubridate)
library(d3heatmap)
library(dplyr)
library(stringr)
library(DT)
# 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",
@MarkEdmondson1234
MarkEdmondson1234 / gist:db2f4946fa11eea2a3f8
Last active February 21, 2020 20:52
Google Trend Download example
## uncomment this and install from github if you don't have it already
# library(devtools)
# devtools::install_github("dvanclev/GTrendsR")
## load library
library(GTrendsR)
## create a connection with your gooooogle account details.
ch <- gconnect('your google email', 'your google pw')
@MarkEdmondson1234
MarkEdmondson1234 / casualImpact_shiny.r
Last active August 29, 2015 14:15
CausalImpact in Shiny
## in server.r of a shiny app
casualImpactData <- reactive({
## only if we have the data ready
validate(
need(chartData(), "Need data")
)
data <- chartData()
@MarkEdmondson1234
MarkEdmondson1234 / dygraph_plot.r
Last active May 31, 2017 08:53
An example of rendering a Dygraph plot in Shiny
## in server.r
output$null_plot <- renderDygraph({
## don't output anything unless you have the data ready
validate(
need(casualImpactData(), "Model Working")
)
## the data for the plot is in here
ci <- casualImpactData()$series