...
 
Commits (2)
......@@ -6,6 +6,13 @@ import(shiny)
importFrom(DBI,dbGetQuery)
importFrom(data.table,":=")
importFrom(data.table,data.table)
importFrom(dygraphs,dyOptions)
importFrom(dygraphs,dyRangeSelector)
importFrom(dygraphs,dygraph)
importFrom(dygraphs,dygraphOutput)
importFrom(dygraphs,renderDygraph)
importFrom(golem,with_golem_options)
importFrom(magrittr,'%>%')
importFrom(pool,dbPool)
importFrom(pool,poolClose)
importFrom(shiny,shinyApp)
......@@ -3,17 +3,23 @@
#' @importFrom pool dbPool
#' @importFrom DBI dbGetQuery
#' @importFrom data.table data.table ":="
#' @importFrom dygraphs dygraph dyRangeSelector renderDygraph
#' @importFrom magrittr '%>%'
app_server <- function(input, output, session) {
output$dispo_over_time <- renderPlot({
output$dispo_over_time <- renderDygraph({
q <- paste0("SELECT last_update_fme, available_bikes ",
"FROM dispo ",
"WHERE number = ", input$number_choice)
dt <- data.table(dbGetQuery(pool, q))
# browser()
dt[, last_update_fme := as.POSIXct(last_update_fme)]
ggplot(dt, aes(x = last_update_fme, y = available_bikes)) +
geom_line()
dygraph(dt,
main = paste0("Disponibilité Vélo'v pour la station ",
input$number_choice)) %>%
dyRangeSelector %>%
dyOptions(colors = "#00225F")
})
}
#' @import shiny
#' @importFrom DBI dbGetQuery
#' @importFrom dygraphs dygraphOutput dyOptions
app_ui <- function() {
q <- "SELECT DISTINCT number FROM dispo"
choices <- dbGetQuery(pool, q)$number
q <- "SELECT DISTINCT name FROM dispo"
choices <- dbGetQuery(pool, q)$name
tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
......@@ -11,7 +14,7 @@ app_ui <- function() {
h1("rvelov"),
selectInput("number_choice", "Number:",
choices = choices),
plotOutput("dispo_over_time")
dygraphOutput("dispo_over_time", height = "600px")
)
)
}
......
......@@ -3,6 +3,7 @@
#' @export
#' @importFrom shiny shinyApp
#' @importFrom golem with_golem_options
#' @importFrom pool poolClose
run_app <- function(...) {
pool <<- dbPool(
......
library(data.table)
library(RMySQL)
con <- dbConnect(MySQL(),
user = Sys.getenv("VELOV_USER"),
password = Sys.getenv("VELOV_PASSWORD"),
dbname = Sys.getenv("VELOV_DB"),
host = Sys.getenv("VELOV_HOST"),
port = as.numeric(Sys.getenv("VELOV_PORT")))
if (!"dispo" %in% dbListTables(con)) {
# Create disponibilite table
df <- data.frame(
number = integer(),
pole = character(),
available_bikes = integer(),
code_insee = character(),
lng = numeric(),
availability = character(),
availabilitycode = integer(),
etat = character(),
startdate = character(),
langue = character(),
bike_stands = integer(),
last_update = character(),
available_bike_stands = integer(),
gid = integer(),
titre = character(),
status = character(),
commune = character(),
description = character(),
nature = character(),
bonus = character(),
address2 = character(),
address = character(),
lat = numeric(),
last_update_fme = character(),
enddate = character(),
name = character(),
banking = logical(),
nmarrond = integer()
)
dbWriteTable(con, "dispo", df, overwrite = TRUE)
}
dispo_url <- paste0("https://download.data.grandlyon.com/ws/rdata/",
"jcd_jcdecaux.jcdvelov/all.json")
dt <- jsonlite::fromJSON(dispo_url)$values
dt <- data.table(dt)
dbWriteTable(con, "dispo", dt, append = TRUE)
dbDisconnect(con)