Lab 3: Configuring Database Access for your Application
Lab: Database Connection with Pro Drivers
In this lab, you will:
- Install Posit Professional Drivers for PostgreSQL
- Configure a system-wide DSN
- Test the connection from R and Python
- Deploy content that uses the DSN
The goal of this lab is to deploy a Shiny app that connects to a PostgreSQL database using a system DSN configured on the Connect server. The app visualizes synthetic on-time flight performance data.
The database server is hosted on localhost, the database is named ontime, and the connection uses the following credentials: username posit, password password. The Shiny application uses a DSN named ontime_db to connect to the database.
Using the instructions found in the Pro Drivers Installation guide, install the Posit Professional ODBC Drivers on your Posit Connect server. Make sure to follow the instructions to create the
/etc/odbcinst.inifile which contains the driver names and locations.Install
odbcinstwithsudo apt install odbcinstto check that the drivers for PostgreSQL have been installed correctly by running the following commands that list the names of the installed drivers (you should see[PostgreSQL]in the output). This step is optional but recommended to verify the installation.odbcinst -q -dCreate a system DSN named
ontime_dbusing the PostgreSQL driver, by adding the database connection information provided above to the file/etc/odbc.iniTipHint/etc/odbc.ini
[ontime_db] Driver = PostgreSQL Server = localhost Port = 5432 Database = ontime UID = posit PWD = passwordGo to the web interface of your Posit Connect server, log in as
ashley(username and password are “ashley”), and click on the “Publish” button. Select “Import from Git”, use:https://github.com/fmichonneau/ontime_demofor the URL. Choose “main” for the branch, click on “Next”. Keep “app” as the directory containing themanifest.jsonfile, enter a title for this application (such as “On Time App”) and click “Deploy Content”. This typically takes 3-5 minutes to build and deploy the application.Once the deployment is successful, if you configured the DSN correctly, you should be able to launch the Shiny application and see the data visualizations.