[英]How to update data automatically in shiny dashboard from mysql database?
I want refresh data every hour in my shiny dashboard. 我想每小时在我闪亮的仪表板上刷新数据。 So that the graphs in shinydashboard automatically update hourly basis.
这样,shinydashboard中的图形会每小时自动更新一次。
Is there any source where I can learn or any sample code to practice ? 是否有任何我可以学习的资源或任何示例代码可以练习?
Thank you. 谢谢。
I have got this with invalidateLater
function. 我有
invalidateLater
函数。 In the below code i just tried to get distinct names from a MySQL table. 在下面的代码中,我只是尝试从MySQL表中获得不同的名称。 After running the shinyApp for first time, i have added a unique row to the same table so that after the specified time(i have checked with 60000 ms) we can check whether shiny is getting refreshed or not.
第一次运行ShinyApp之后,我在同一张表中添加了一个唯一的行,以便在指定的时间(我已经检查了60000 ms)之后,我们可以检查Shiny是否正在刷新。 It should display the newly entered name after that specified time.
在指定的时间后,它将显示新输入的名称。 ( Change it to 3600000 ms for your requirement.)
(根据您的要求将其更改为3600000 ms。)
library(shiny)
library(DBI)
library(pool)
pool <- dbPool(drv = RMySQL::MySQL(),dbname = "database",host = "localhost",username = "username",password = "password", port = 3306, unix.sock = "/var/run/mysqld/mysqld.sock")
ui <- fluidPage(
uiOutput("names")
)
server <- function(input, output, session){
getNames <- function(x){
dbGetQuery(x, "SELECT DISTINCT names from dummyTable;")
}
refreshData <- reactive({
invalidateLater(60000, session)
getNames(pool)
})
output$names <- renderUI({
selectInput(inputId = "name", label = "First names", choices = c(as.character(refreshData()[,1])))
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.