#' Connects to a database
#'
#' Connects to a small SQLite DB but it could be any backend
#'
#' @return db_conn. SQLiteConnection
#'
#' @noRd
#'
#' @importFrom DBI dbConnect
#' @importFrom RSQLite SQLite
connect_db <- function() {
dbConnect(SQLite(), system.file("extdata", "bonski.db", package = "bonski.shiny"))
}
#' Inserts predicted skiabilite
#'
#' Inserts content a of dataframe holding predicted skiabilite per routes for a date
#'
#' @param conn SQLiteConnection
#' @param df data.table. Predicted skiabilite
#'
#' @noRd
#'
#' @importFrom DBI dbAppendTable
insert_skiabilite <- function(conn, df) {
dbAppendTable(conn, "skiabilite", df)
}
#' Gets predicted skiabilite
#'
#' Gets the lastest predicted skiabilite data
#'
#' @param conn SQLiteConnection
#'
#' @return data.table.
#'
#' @noRd
#'
#' @importFrom DBI dbGetQuery
get_latest_skiabilite <- function(conn) {
dbGetQuery(
conn,
"SELECT route, skiabilite FROM skiabilite WHERE date = (SELECT max(date) FROM skiabilite)"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.