I am trying to use Shiny App to display 'live process data' of last 5 minutes.
While leaving the app run, after some time it stops displaying the data (it behaves like there is no data available in database) and in console i can see the Error:
ORA-01000: maximum open cursors exceeded
At the moment i am getting live update using invalidateLater()
, below is sample code:
library(ROracle)
library(shiny)
library(ggplot2)
ui <- fluidPage(plotOutput("plot", height=800))
server <- function(input, output, session) {
con=reactiveValues(cc=NULL)
drv <- dbDriver("Oracle")
con$cc<- dbConnect(drv,"xxx",username="xx",password="xx")
observe({
if(!is.null(con$cc)& is(con$cc,"OraConnection")){ # check if connected
output$test <- renderText({
"Verbindung zur Datenbank erfolgreich hergestellt"
})
sqlOutput <- reactive({
withProgress(message = 'Processing...', style = "old", value = 0,
{
for (i in 1:10) {
incProgress(1/30)
Sys.sleep(0.1)
}
invalidateLater(5000, session) # Invalidates MyData after 5000 millisecs = 5 secs.
rs <- dbSendQuery(con$cc, paste("select * from XX where Time >= SYSDATE - 5/(24*60) order by Time asc"))
sqlOutput <- fetch(rs)
sqlOutput
})})
testplot <- function(){
g <-ggplot(data=sqlOutput(),aes(x=x, y=x))+ geom_line()
g
}
output$plot <- renderPlot({testplot()})
}else if (!is.null(con$cc) ){
output$test <- renderText({
con$cc
})
}
})
session$onSessionEnded(function() {
observe({
if(!is.null(con$cc)& is(con$cc,"OraConnection")){# check if connected
print(paste0("disconnect ",dbDisconnect(con$cc)))}
})
})
}
shinyApp(ui = ui, server = server)
I have seen another posts on stackoverflow having same problem, however they are not using R, rather java.
Additionaly i know that the db user i am using has two connections open to database (as i have two shiny apps displaying 'live' views).
Maybe someone has better idea how to make it work and pool the data to R constantly (every 5 seconds) from oracle database without encountering this error.
I have been researching a bit and came across pool
package. Is dbpool()
function gonna solve the problem of maximum open cursors?