03_databse/app.R is a Shiny application that reads data from a PostGres database.
The RStudio IDE has a pane for “Connections” that allows you to establish database connections and browse information contained in the database tables.
See these support articles:
As well as the article at https://db.rstudio.com/
And you can watch this video walkthrough:
Run the app
03_database/app.R in the IDE to make sure everything works.
Notice that the connection gets established by this line of R code:
con <- DBI::dbConnect(odbc::odbc(), "Postgres Dev")
03_database/app.R to Connect (using the publish button in the Source pane).
While you wait, can you figure out how “PostGres Dev” is defined?
cat /etc/odbc.ini cat /etc/odbcinst.ini
While you’re viewing the deployed app in Connect, find the “runtime settings”:
The Connect admin guide explains these settings at:
Read this part of the admin guide, then change the settings to allow parallel execution of your app:
|Max connections per process||2|
The setting pane looks like this:
Open the metrics dashboard in a new browser tab
Return to your app, and progressively open the app in 6 new tabs
Notice in this recording how the CPU indicator goes into the red very quickly, as each shiny connection puts a new demand on the database. However, even a 2CPU machine can handle the 6 simultaneous connections, albeit with some delay to the user:
Shimmer and shiny simulation app at https://colorado.rstudio.com/rsc/shimmer_and_shiny/
Try to develop an intuitive understanding of the runtime settings.
Ideas to try:
Then modify the server size and runtime settings until all the indicators are in the “blue”