我在Azure中的Ubuntu VM中运行了一个Shiny Server。
如何每天晚上安排server.R中的mysql查询?如何在每次访问应用程序时避免运行它们?
这是我的服务器示例.R和ui.R:
server.R
library(shiny)
library(RMySQL)
library(ggplot2)
#library(ggiraph)
library(lubridate)
##Connect to Redmine db
con <- dbConnect(MySQL(),
user = '#',
password = '#',
host = '#',
dbname='#')
tickets<-dbGetQuery(con, "Select * from table")
issues_speed_unique<-unique(na.omit(dbGetQuery(con,"Select * from table2")))
dbDisconnect (con)
some aggregations....
shinyServer(
function(input,output){
ui.R
library(shiny)
library(ggplot2)
#library(ggiraph)
#library(htmltools)
library(lubridate)
shinyUI(fluidPage(
答案 0 :(得分:0)
filename <- paste0(Sys.Date(),'.RData')
if (!file.exists(filename)){
# don't have a cached copy so run the query
library(RMySQL)
con <- dbConnect(MySQL(),
user = '#',
password = '#',
host = '#',
dbname='#')
tickets<-dbGetQuery(con, "Select * from table")
issues_speed_unique<-unique(na.omit(dbGetQuery(con,"Select * from table2")))
dbDisconnect (con)
# save the query results for the future
save(list=c('tickets', 'issues_speed_unique'), file=filename)
rm(list=c('tickets', 'issues_speed_unique') )
}
load(file=filename)