问题描述
我已经使用闪亮的Shinydashboard和RMySQL软件包制作了仪表板.以下是我写的内容,以便每10分钟刷新一次数据.
I've made dashboard using shiny, shinydashboard and RMySQL package.Following is what I wrote in order to refresh data every 10 minutes if any change occured.
在global.R
con = dbConnect(MySQL(), host, user, pass, db)
check_func <- function() {dbGetQuery(con, check_query}
get_func <- function() {dbGetQuery(con, get_query}
在server.R
function(input, output, session) {
# check every 10 minutes for any change
data <- reactivePoll(10*60*1000, session, checkFunc = check_func, valueFunc = get_func)
session$onSessionEnded(function() {dbDisconnect(con)})
但是,以上代码很少会从check_func生成损坏的连接句柄错误.
However, above code infrequently generates corrupt connection handle error from check_func.
Warning: Error in .local: internal error in RS_DBI_getConnection: corrupt connection handle
我应该将dbConnect代码放入服务器功能中吗?还有更好的主意吗?
Should I put dbConnect code inside server function? Any better ideas?
链接:使用session $ onsessionend断开rshiny mysql服务器上的应用程序
推荐答案
"pool"包是答案: http://shiny.rstudio.com/articles/pool-basics.html
"pool" package is the answer: http://shiny.rstudio.com/articles/pool-basics.html
我从这里得到了答案. -> https://stackoverflow.com/a/39661853/4672289
I've got answer from here. -> https://stackoverflow.com/a/39661853/4672289
这篇关于在Shiny应用程序中,如果发生任何更改,如何每10分钟从MySQL db刷新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!