简体   繁体   English

如何从MySQL数据库自动更新闪亮仪表板中的数据?

[英]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.

相关问题 如何从闪亮的仪表板上下载条形图数据? - How to download data of bar chart from shiny dashboard? R Shiny Dashboard:从本地文件和在线数据库(如Google Sheet)上传数据 - R Shiny Dashboard: Upload data from both local file and the online database (such as Google Sheet) 通过Shiny应用程序更新表数据库SQL Server中的数据 - Update data from table database SQL Server through Shiny app 如何使用 Flexdashboard 和 Shiny 将 web 服务中的数据“正确”加载到 Rmarkdown 中的仪表板中? - How to "correctly" load data from a web service into a dashboard in Rmarkdown with Flexdashboard and Shiny? 如何将闪亮的应用程序中的反应性输入值插入MySQL数据库? - How to insert reactive input values from a shiny app into a MySQL database? 来自selectInput的闪亮更新数据 - Shiny update data from selectInput 如何在Shiny应用程序的仪表板主体中输出数据库表? - How to output Database table in the dashboard body in Shiny app? 使用 Reactable.getState 从 shiny 仪表板的嵌套反应中获取数据 - Get data from nested reactable of shiny dashboard with Reactable.getState 闪亮仪表板内的数据抑制 - Data suppression within Shiny Dashboard 闪亮的仪表板数据刷新触发器 - Shiny dashboard data refresh trigger
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM