-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.R
86 lines (64 loc) · 2.36 KB
/
global.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Chargement des données
# install.packages(c('plyr', 'plotly', 'ggplot2', 'scales', 'data.table', 'DT',
# 'shinyjs', 'stringr', 'leaflet', 'magrittr', 'pool',
# 'RPostgreSQL', 'glue', 'askpass', 'writexl'))
library(shiny)
library(plyr)
library(plotly)
library(ggplot2)
library(scales)
library(data.table)
library(DT)
library(shinyjs)
library(stringr)
library(leaflet)
library(magrittr)
library(pool)
library(RPostgreSQL)
library(glue)
# library(RODBCext)
library(askpass)
library(writexl)
options(shiny.sanitize.errors = FALSE)
options(digits = 4, scipen=999)
options(shiny.usecairo=T, shiny.reactlog = T, stringsAsFactors = FALSE)
# A appliquer à toutes les requêtes SQL pour gérer l'encodage
set_utf8 <- function(x) {
chr = sapply(x, is.character)
x[, chr] = lapply(x[, chr, drop = FALSE], `Encoding<-`, "UTF-8")
Encoding(names(x)) = "UTF-8"
x
}
# Chargement des données. Encodage UTF-8
departements = read.csv('donneesComplementaires/departement.csv', stringsAsFactors = F,
colClasses = 'character')
departements$codeDep = gsub('^\\s+', '', formatC(departements$codeDep, width = 2, flag = '0'))
departements$label = sprintf('%s (%s)', departements$nomDepMin, departements$codeDep)
cpv = read.csv2('donneesComplementaires/genealogie_cpv.csv',
stringsAsFactors = F, colClasses = "character")
cpv$genealogieLabel = NULL
# Création de la connection PSQL
config = readLines('config.csv')
print("Starting new connection")
con <- dbPool(
drv = dbDriver("PostgreSQL", max.con = 100),
dbname = "decp",
host = config[3],
user = config[1],
password = config[2],
idleTimeout = 360000
)
print("Done new connection")
formesContratConcession = c("Concession de travaux", "Concession de service",
"Concession de service public", "Délégation de service public")
formesMarche = c("Marché", "Marché de partenariat", "Accord-cadre", 'Marché subséquent')
# Acheteurs et Titulaires
acheteurs = dbGetQuery(con, "SELECT DISTINCT * from liste_acheteurs")
listeAcheteurs = sort(acheteurs$nomsirenacheteur)
titulaires = dbGetQuery(con, "SELECT DISTINCT * from liste_titulaires")
listeTitulaires = sort(titulaires$nomsirentitulaire)
################### Vision globale
labelMultiLigne = function(chaine){
chaine = paste(strwrap(chaine, width=40), collapse = '\n')
return(chaine)
}