Data Analysis Workstation
Run the pfda-ttyd Featured App
Using the smallest instance type, run the Data Analysis Workstation job using the pfda-ttyd featured app.



Refresh the execution status using the refresh button until the job is running and open the workstation.


Use dx-get-timeout and dx-set-timeout to view and set the workstation application time-to-live after which it will self-terminate.
Present a simple web server on port 8080
The ttyd and guacamole workstations enable presentation of web services that can be accessed via the job URL port 8080. Let's startup a simple Python-based web server and browse to it.
Now copy the URL from your ttyd window and append port 8080 to it(e.g. https://job-gxjjzj80kj2qgp2z6p9x1yvq.dnanexus.cloud:8080) to browse to your web service on the wo rkstation.

Kill the http.server job to free up port 8080.
Deploy PostgreSQL, psql, pgadmin, and RStudio
A docker-compose.yml file is configured to launch a local PostgreSQL database, and RStudio, and pgadmin web services that connect to the database. RStudio and pgadmin are accessed using the workstation job URL extended to target the specific service on port 8080 (e.g. https://job-gb1y8jj0kj2xvbggbp3qgv55.dnanexus.cloud:8080/pgadmin/). The postgres-local database container is accessed from the pgadmin and rstudio containers and from the psql command line client on the workstation shell.
The pfda-ttyd and guacamole workstation apps provide port 8080 for access to user deployed web services on the workstation. In order to access multiple different web services (e.g. pgadmin and RStudio) on the single port 8080, a Docker-based reverse proxy is configured using the traefik open source cloud-native application proxy application (https://github.com/traefik/traefik).
Install docker-compose-plugin.
Download the traefik-postgres-pgadmin-rstudio-docker-compose.yml file to the workstation.
Start the traefik, postgres-local, rstudio, and pgadmin docker services.
Install the psql postgres command line client and test the connection to the database.
Ctrl-D to exit psql.
Configure the pgadmin container mounted directory permissions.
Access the postgres-local DB from pgadmin
Access the pgadmin web service from your web browser (e.g. https://job-gk0qpfj0kj2ybz63p36by5kj.dnanexus.cloud:8080/pgadmin).
Add the workstation local database as a new server (e.g. Data Analysis Workstation DB Server) using hostname postgres-local and port 5432, maintenance database postgres, user postgres, and password password.


Create a new database and tables
Connect to the cluster database from psql in the data analysis workstation shell.
Using psql, create a new database.
Connect to the new database and create two tables.
Load the cluster database from delimited text files
In the data analysis workstation shell, create a datafiles directory
Create file patients.txt with the following content:
Create file observations.txt with the following content:
Copy the data into the cluster DB tables
In psql:
Observe the new tables and data in the pgadmin Workstations and Databases Tutorial server connection.
Share Files Between Workstation FS and PostgreSQL Docker FS
Since pgadmin is running in a Docker container on the workstation, we are going to have to connect to the pgadmin container shell and copy files we want to share between the workstation and pgadmin to and from the mount point shared by the container and the workstation (i.e. /home/dnanexus/db_backups).
When performing a database backup in pgadmin, save the file in /home/dnanexus/db_backups.

The backup file is accessible in workstation /home/dnanexus/db_backups. Files can be placed in this directory for access by pgadmin.
Access the postgres-local DB from rstudio
Access the RStudio web service from your web browser (e.g. https://job-gb1y8jj0kj2xvbggbp3qgv55.dnanexus.cloud:8080/rstudio/).

Install the RPostgres packages and test access to the workstation local database. In the R Studio console:
Since there are no tables in the postgres database, the response is character(0). Let’s add two tables using psql and run the same R query. Using the psql command line client in the data analysis workstation shell:
The same query in the RStudio console now shows the two new tables.
Let’s drop the tables since we will be populating this database from a backup a later stage in this tutorial. Using the psql command line client in the data analysis workstation shell:
Control-D to exit psql.
Share Files Between Workstation FS and RStudio Docker FS
The rstudio container shares the /home/dnanexus mount point with the workstation filesystem so it straightforward to access the workstation filesystem from within RStudio. Simply set the path in the RStudio file browser to /home/rstudio/dnanexus.
PostgreSQL Tips
Force drop connections
If you need to drop a database, you’ll need to close all the sessions connected to it using the following postgreSQL code:
Quick queries for estimated row counts
To present the estimated row count for each table:
To present to total row count for all tables: