auto update data for shiny app

Hello guys,

I'd like to update the shiny app every minute with the data get from both mysql and sqlserver... I have no clue on how to do that, any suggestion would be appreciated!

Here is an example of the code

library(DT)	
library(DBI)
library(RMySQL)
library(dplyr)
library(stringr)
	
ui <- basicPage(
             h2("GetBasis"),
  	     DT::dataTableOutput("dtgetbasis")
)

server <- function(input, output) {
	sqlserver <- DBI::dbConnect(odbc::odbc(),
                  Driver = "ODBC Driver 17 for SQL Server", 
                  Server = "mySQLserver", 
                  Database = "mydatabase", 
                  UID = "myuid", 
                  PWD = "mypassword", 
                  Port = myport)

	mysql <- dbConnect(MySQL(), 
             user = 'myMYSQLserver', 
             password = 'mypassword', 
             dbname = 'mydatabase', 
             host = 'myhost')

	query_1 <- "SELECT 
       				someting
			    FROM
				[somedbo].[somedata] 
			    WHERE 
  				something"
	query_2 <- "SELECT 
       				someting
  			    FROM
  				 [somedbo].[somedata] 
  			    WHERE 
  				 something"

	data1 <- dbGetQuery(mysql,query_2)
	data2 <- dbGetQuery(sqlserver,query_1)
 
	data <- inner_join(data1,  data2)
	attach(data)
        detach(data)

	output$dtgetbasis = DT::renderDataTable({data})
}
shinyApp(ui, server)

Thank you in advanced

Take a look at the reactivePoll() function, it is designed to do exactly that.

https://shiny.rstudio.com/reference/shiny/latest/reactivePoll.html

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.