-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseShiny.R
51 lines (39 loc) · 1.41 KB
/
DatabaseShiny.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
library(RMySQL)
options(mysql = list(
"host" = "10.0.160.45",
"port" = 3306,
"user" = "paulreilly",
"password" = "ut5bTEALj4Ff8WrZ"))
databaseName <- "ranking-report"
table <- "rankings-history"
now <- as.Date(Sys.Date())
lag <- 90
clientID <- 63
loadData <- function() {
# Connect to the database
db <- dbConnect(MySQL(), dbname = databaseName, host = options()$mysql$host,
port = options()$mysql$port, user = options()$mysql$user,
password = options()$mysql$password)
#Contruct Query ========
query <- sprintf("SELECT rh.date, kw.category, rh.keyword, rh.position, rh.host, kw.country FROM \`rankings-history\` rh join keywords kw WHERE rh.keyword = kw.keyword AND kw.client=%s AND rh.date >= \'%s\' and rh.date < \'%s\' ", clientID, (now - (lag+1)),(now-lag))
query
# Submit the fetch query and disconnect
data <- dbGetQuery(db, query)
dbDisconnect(db)
data
}
ShowClientIDs <- function() {
# Connect to the database
db <- dbConnect(MySQL(), dbname = databaseName, host = options()$mysql$host,
port = options()$mysql$port, user = options()$mysql$user,
password = options()$mysql$password)
#Contruct Query ========
query <- ("SELECT * from \`clients\`")
query
# Submit the fetch query and disconnect
data <- dbGetQuery(db, query)
dbDisconnect(db)
data
}
df <- loadData()
clients <- ShowClientIDs()