Skip to content

Commit

Permalink
update prod app to use ADKP data model (#20)
Browse files Browse the repository at this point in the history
* Update ui.R

Added EL to name

* Update ui.R

* Revert "Update ui.R"

This reverts commit 361b669.

* Revert "Merge pull request #14 from nlee-sage/master"

This reverts commit 169e4ab, reversing
changes made to c1d59fe.

* remove renv artifacts

* re-install renv and packages

* replace synapse table with data model csv

* remove reticulate and synapseclient deps

* add data model url to global vars

* use data model csv instead of synapse table

* adjust reactable column definitions

* edit ui instruction display

* update reactable output

* remove shinyapps.io workflow

* add shinylive -> gh pages deployment workflow

* update renv lockfile

* update rproj settings

* ignore shinylive site assets

* remove tibble dep

* rename workflow to specify shinylive

* restore shinyapps.io workflow

* fix column display

* add workflow dispatch and rename for clarity

* force app to update

* allow job to run via workflow dispatch trigger

* don't run shinylive deploy when PR opened

* clarify workflow process

* update ui message

* bumb checkout version

* don't disable renv (didn't work anyway)

* update to latest version of workflow from r-lib

* don't install from renv during gh action

* don't install from renv during action

* definitely need renv

* ignore large directories during rsconnect deploy

* rsconnect ignore Rprofile

* rename rsconnect ignore file

* this wasn't the right file name

* setting appFiles to all files overrides .rscignore

* Update README.md

* Update README.md

---------

Co-authored-by: Nicholas Lee <[email protected]>
Co-authored-by: j-hendrickson-sage <[email protected]>
  • Loading branch information
3 people authored Aug 22, 2024
1 parent aee0766 commit 506060b
Show file tree
Hide file tree
Showing 18 changed files with 1,851 additions and 382 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
^\.github$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
source("renv/activate.R")

1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
50 changes: 50 additions & 0 deletions .github/workflows/deploy-shinyapps-io.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help

name: shinyapps-io-deploy

# run when PR is merged OR via workflow dispatch
on:
pull_request:
types:
- closed
workflow_dispatch:

jobs:
shinyapps-io-deploy:
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-renv@v2

- name: Install rsconnect
run: install.packages("rsconnect")
shell: Rscript {0}

- name: Authorize and deploy app
run: |
branch<-Sys.getenv("GITHUB_REF_NAME")
repo<-Sys.getenv("GITHUB_REPOSITORY")
appName<-strsplit(repo, "/")[[1]][2]
if (!startsWith(branch, "prod")) {
appName = paste(appName, "staging", sep="-")
}
rsConnectUser <-"${{ secrets.RSCONNECT_USER }}"
rsConnectToken <- "${{ secrets.RSCONNECT_TOKEN }}"
rsConnectSecret <- "${{ secrets.RSCONNECT_SECRET }}"
rsconnect::setAccountInfo(rsConnectUser, rsConnectToken, rsConnectSecret)
# appDir default is current working directory
rsconnect::deployApp(appName = appName, forceUpdate = TRUE)
# important NOT to run this step as sudo, otherwise env var's will be missing
shell: Rscript {0}
21 changes: 21 additions & 0 deletions .github/workflows/deploy-shinylive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Workflow derived from https://github.com/posit-dev/r-shinylive/tree/actions-v1/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
#
# Basic example of a GitHub Actions workflow that builds a Shiny app and deploys
# it to GitHub Pages.
name: Deploy app to gh-pages

on:
# Manually trigger the workflow
workflow_dispatch:
# Trigger on push to `main` branch
push:
branches: "main"

jobs:
shinylive:
uses: posit-dev/r-shinylive/.github/workflows/deploy-app.yaml@actions-v1
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
55 changes: 0 additions & 55 deletions .github/workflows/shinyapps_deploy.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.DS_Store
.project
.settings/
site/*
6 changes: 6 additions & 0 deletions .rscignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
renv/
.Rprofile
.git/
.Rproj.user/
*.Rproj
*.log
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
# AMP-AD Metadata Dictionary

Hosts the dictionary used for metadata in AMP-AD, which is composed of the
[synapseAnnotations](https://github.com/Sage-Bionetworks/synapseAnnotations/) as
well as some custom values that are used only in metadata files, and not as
annotations.
Hosts the dictionary used for metadata in AMP-AD, which is a ReacTable object that displays the production [ADKP data model](https://github.com/adknowledgeportal/data-models/blob/main/AD.model.csv).

The dictionary app displays all attributes used as manifest columns, and all valid values for those columns. It does not display manifest attributes (where Parent = 'ManifestTemplate').

As of August 2024, this app no longer interacts with Synapse since it is pulling from the ADKP data model used for schematic and DCA. The recitulate and synapsclient dependencies have been removed.

### To deploy to ShinyApps.io:

- Enable workflows in the GitHub repository
- Under [secrets](https://github.com/Sage-Bionetworks/amp-ad-metadata-dictionary/settings/secrets/actions) click 'New repository secret'
- Enter secrets for `RSCONNECT_USER`, `RSCONNECT_TOKEN`, and `RSCONNECT_SECRET`, the values for which are saved in Sage's LastPass.
- Push to new branch on Github
- Create pull request with at least one reviewer to master branch
- Upon merge of pull request, the app will deploy to staging.
The shinyapps.io deployment workflow is `deploy-shinyapps-io.yaml`.
- This uses repository secrets to deploy the app to ShinyApps.io via rsconnect: `RSCONNECT_USER`, `RSCONNECT_TOKEN`, and `RSCONNECT_SECRET`. Values for these are saved in Sage's LastPass.
- This workflow runs when a PR is approved and merged into, OR via manual workflow dispatch
- Upon completion of the workflow, the app will deploy to staging.
Check out the app here: https://sagebio.shinyapps.io/amp-ad-metadata-dictionary-staging.
- After verifying correctness, create pull request with at least one reviewer to prod branch
- After verifying correctness on `main`, create pull request with at least one reviewer to `prod` branch
- Upon merge of pull request, the app will deploy to production.
- The app' will become available at https://sagebio.shinyapps.io/amp-ad-metadata-dictionary
- The production app will become available at https://sagebio.shinyapps.io/amp-ad-metadata-dictionary
- This app is embedded as an iframe on the Synapse wiki here: https://www.synapse.org/Synapse:syn25878249

### To deploy to Github Pages via shinylive:

The shinylive deployment workflow is `deploy-shinylive.yaml`.
- This uses the `shinylive` package to build a static site that is run entirely in the browser (https://posit-dev.github.io/r-shinylive/), and deploy that site to Github pages
- This workflow runs on a push to `main` or via workflow dispatch
- ⚠️ right now this site loads very, very slowly. The static site will not replace the shinyapps.io deployment as our user-facing version unless we can figure out how to speed it up.
5 changes: 5 additions & 0 deletions amp-ad-metadata-dictionary.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

UseNativePipeOperator: Yes
65 changes: 41 additions & 24 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
suppressPackageStartupMessages(library("dplyr"))
suppressPackageStartupMessages(library("purrr"))
suppressPackageStartupMessages(library("reactable"))
suppressPackageStartupMessages(library("reticulate"))
suppressPackageStartupMessages(library("shiny"))

if (Sys.getenv("R_CONFIG_ACTIVE") == "shinyapps") {
venv_folder<-"virtual_env"
if (!file.exists(venv_folder)) {
reticulate::virtualenv_create(envname = venv_folder, python = '/usr/bin/python3')
reticulate::virtualenv_install(venv_folder, packages = c('synapseclient', 'pandas'))
}
reticulate::use_virtualenv(venv_folder, required = T)
}

## Load synapse client
# reticulate::use_condaenv("synapse")
synapse <- reticulate::import("synapseclient")
## Global variables
data_model_url <- "https://raw.githubusercontent.com/adknowledgeportal/data-models/main/AD.model.csv"

## Function to truncate display in table
truncated_values <- JS("
Expand All @@ -29,15 +18,43 @@ truncated_values <- JS("
}
")

get_synapse_table <- function(synID, syn) {
query_result <- syn$tableQuery(
glue::glue("select * from {synID}"),
includeRowIdAndRowVersion = FALSE
)
dat <- utils::read.csv(
query_result$filepath,
na.strings = "",
stringsAsFactors = FALSE
)
dat
#' Format a Data Dictionary Table
#'
#' This function reads a schematic-formated data model csv from a raw github url and formats the data frame for use in the AD metadata dictionary shiny app.
#'
#' @param data_model_url A character string specifying the URL of the CSV file containing the data model.
#' @return A tibble containing the formatted data dictionary with columns, descriptions, and associated attributes.
#' @import dplyr
#' @importFrom utils read.csv
#' @importFrom stats url
#' @export
format_dict_table <- function(data_model_url) {

data_model <- read.csv(url(data_model_url))

col_attribs <- data_model |>
dplyr::filter(Parent == 'ManifestColumn') |>
dplyr::select(
Column = Attribute,
`Column Description` = Description,
Required,
`Column Type` = columnType,
`Data Model Module` = module
)

val_attribs <- data_model |>
dplyr::filter(Parent %in% col_attribs$Column) |>
dplyr::select(
Value = Attribute,
`Value Description` = Description,
Source,
Column = Parent
)

dict_table <- col_attribs |>
dplyr::left_join(val_attribs, relationship = "many-to-many") |>
dplyr::relocate(`Data Model Module`, .after = Source)

return(dict_table)

}
Loading

0 comments on commit 506060b

Please sign in to comment.