Skip to content

Instantly share code, notes, and snippets.

@cecilialee
Last active February 23, 2018 07:47
Show Gist options
  • Select an option

  • Save cecilialee/80dfb7bae4b2e7f8fba81391096a1bb3 to your computer and use it in GitHub Desktop.

Select an option

Save cecilialee/80dfb7bae4b2e7f8fba81391096a1bb3 to your computer and use it in GitHub Desktop.
Disconnect database on session ended in Shiny. #r #shiny #dbi
library(shiny)
library(DBI)
library(RPostgreSQL)
ui = basicPage(
)
server = function(input, output, session) {
con <- dbConnect(PostgreSQL(),
dbname = "myDB",
host = "12.10.11.901",
user = "user",
password = "password")
session$onSessionEnded(function() {
dbDisconnect(con)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment