...
 
Commits (3)
Package: rvelov
Title: Visualize Velo'v availability and predictions
Version: 0.0.0.9000
Version: 0.0.1
Authors@R: person('Charles', 'Bordet', email = 'charles@datachamp.fr', role = c('cre', 'aut'))
Description: Visualize the availability of all Velo'v stations
through a Shiny app, and predictions of future availability. Users of this
......@@ -11,5 +11,7 @@ LazyData: true
Imports:
shiny,
golem,
htmltools
htmltools,
pool,
ggplot2
RoxygenNote: 6.1.1
FROM rocker/tidyverse:3.6.1
RUN R -e 'install.packages("remotes")'
RUN R -e 'remotes::install_github("r-lib/remotes", ref = "97bbf81")'
RUN R -e 'remotes::install_cran("shiny")'
RUN R -e 'remotes::install_cran("golem")'
RUN R -e 'remotes::install_cran("htmltools")'
COPY rvelov_*.tar.gz /app.tar.gz
RUN R -e 'remotes::install_local("/app.tar.gz")'
EXPOSE 80
CMD R -e "options('shiny.port'=4848,shiny.host='0.0.0.0');rvelov::run_app()"
# Generated by roxygen2: do not edit by hand
export(run_app)
import(ggplot2)
import(shiny)
importFrom(DBI,dbGetQuery)
importFrom(data.table,":=")
importFrom(data.table,data.table)
importFrom(golem,with_golem_options)
importFrom(pool,dbPool)
importFrom(pool,poolClose)
importFrom(shiny,shinyApp)
# rvelov 0.0.1
* Added a selector to choose the station number
* Added a chart to visualize the availability over time
* Added Dockerfile for deployment
# rvelov 0.0.0.9000
* Added a `NEWS.md` file to track changes to the package.
#' @importFrom pool dbPool poolClose
app_global <- function() {
pool <- dbPool(
drv = RMySQL::MySQL(),
dbname = Sys.getenv("VELOV_DB"),
user = Sys.getenv("VELOV_USER"),
password = Sys.getenv("VELOV_PASSWORD"),
host = Sys.getenv("VELOV_HOST"),
port = as.numeric(Sys.getenv("VELOV_PORT")))
onStop(function() {
poolClose(pool)
})
}
#' @import shiny
app_server <- function(input, output,session) {
# List the first level callModules here
#' @import ggplot2
#' @importFrom pool dbPool
#' @importFrom DBI dbGetQuery
#' @importFrom data.table data.table ":="
app_server <- function(input, output, session) {
output$dispo_over_time <- renderPlot({
q <- paste0("SELECT last_update_fme, available_bikes ",
"FROM dispo ",
"WHERE number = ", input$number_choice)
dt <- data.table(dbGetQuery(pool, q))
dt[, last_update_fme := as.POSIXct(last_update_fme)]
ggplot(dt, aes(x = last_update_fme, y = available_bikes)) +
geom_line()
})
}
#' @import shiny
#' @importFrom DBI dbGetQuery
app_ui <- function() {
q <- "SELECT DISTINCT number FROM dispo"
choices <- dbGetQuery(pool, q)$number
tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
# List the first level UI elements here
fluidPage(
h1("rvelov")
h1("rvelov"),
selectInput("number_choice", "Number:",
choices = choices),
plotOutput("dispo_over_time")
)
)
}
......
#' Import all data from database
#'
#' @param pool pool
#'
#' @importFrom data.table data.table
#' @importFrom DBI dbGetQuery
import_all_data <- function(pool) {
q <- "SELECT * FROM dispo"
dt <- data.table(dbGetQuery(pool, q))
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
#' @importFrom golem with_golem_options
run_app <- function(...) {
with_golem_options(
app = shinyApp(ui = app_ui, server = app_server),
app = shinyApp(ui = app_ui, server = app_server, onStart = app_global),
golem_opts = list(...)
)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/r_import.R
\name{import_all_data}
\alias{import_all_data}
\title{Import all data from database}
\usage{
import_all_data(pool)
}
\arguments{
\item{pool}{pool}
}
\description{
Import all data from database
}