Skip to content

Commit

Permalink
Merge pull request #236 from Sage-Bionetworks/fds-1615-json-config
Browse files Browse the repository at this point in the history
FDS-1615: Refactor to handle JSON configuration
  • Loading branch information
lakikowolfe authored Feb 23, 2024
2 parents fb7bfd1 + ca89f0a commit 889fdde
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 57 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dataflow
Title: Data Flow App Demo
Version: 23.10.1
Version: 24.2.1
Authors@R: person('L', 'Wolfe', email = 'loren.wolfe@sagebase.org', role = c('cre', 'aut'))
Description: A data flow package.
License: MIT + file LICENSE
Expand Down
90 changes: 56 additions & 34 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ app_server <- function( input, output, session ) {
)

# get the access_token and userinfo token
req <- httr::POST(redirect_url,
encode = "form",
body = "",
httr::authenticate(app$key, app$secret, type = "basic"),
config = list())
req <- httr::POST(
redirect_url,
encode = "form",
body = "",
httr::authenticate(app$key, app$secret, type = "basic"),
config = list()
)
# Stop the code if anything other than 2XX status code is returned

httr::stop_for_status(req, task = "get an access token")
Expand Down Expand Up @@ -61,17 +63,21 @@ app_server <- function( input, output, session ) {


# SELECT A DCC #############################################################
mod_select_dcc_out <- dfamodules::mod_select_dcc_server("select_dcc",
dcc_config,
access_token)
mod_select_dcc_out <- dfamodules::mod_select_dcc_server(
id = "select_dcc",
tenants_config_path = tenants_config_path ,
access_token = access_token
)

# CONFIGURE APP ############################################################
observeEvent(mod_select_dcc_out()$btn_click, {

# move to dashboard page
shinydashboard::updateTabItems(session = session,
inputId = "tabs",
selected = "tab_dashboard")
shinydashboard::updateTabItems(
session = session,
inputId = "tabs",
selected = "tab_dashboard"
)

# show waiter on button click
waiter::waiter_show(
Expand All @@ -85,12 +91,23 @@ app_server <- function( input, output, session ) {
shinyjs::show(selector = ".sidebar-menu")

# update reactiveVals
selected_dcc_config_list$synapse_asset_view(mod_select_dcc_out()$selected_dcc_config$synapse_asset_view)
selected_dcc_config_list$manifest_dataset_id(mod_select_dcc_out()$selected_dcc_config$manifest_dataset_id)
selected_dcc_config_list$project_name(mod_select_dcc_out()$selected_dcc_config$project_name)
selected_dcc_config_list$schema_url(mod_select_dcc_out()$selected_dcc_config$schema_url)
selected_dcc_config_list$icon(mod_select_dcc_out()$selected_dcc_config$icon)
selected_dcc_config_list$synapse_asset_view(
mod_select_dcc_out()$selected_dcc_config$dcc$synapse_asset_view
)
selected_dcc_config_list$manifest_dataset_id(
mod_select_dcc_out()$selected_dcc_config$dcc$manifest_dataset_id
)
selected_dcc_config_list$project_name(
mod_select_dcc_out()$selected_dcc_config$dcc$name
)
selected_dcc_config_list$schema_url(
mod_select_dcc_out()$selected_dcc_config$dcc$data_model_url
)
selected_dcc_config_list$icon(
mod_select_dcc_out()$selected_dcc_config$dfa_dashboard$icon
)

# Check that user has appropriate permissions to use DFA
# User must have DOWNLOAD access to the DFA manifest.
manifest_perm <- dfamodules::synapse_access(
id = selected_dcc_config_list$manifest_dataset_id(),
Expand All @@ -114,10 +131,12 @@ app_server <- function( input, output, session ) {
waiter::waiter_hide()
}

# generate dashboard config file
dash_config <- dfamodules::generate_dashboard_config(
schema_url = selected_dcc_config_list$schema_url(),
icon = selected_dcc_config_list$icon(),
base_url = schematic_api_url)
base_url = schematic_api_url
)

# download manifest
manifest_obj <- dfamodules::dataset_manifest_download(
Expand All @@ -126,36 +145,36 @@ app_server <- function( input, output, session ) {
access_token = access_token,
base_url = schematic_api_url
)

# prep manifest for app
prepped_manifest <- dfamodules::prep_manifest_dfa(
manifest = manifest_obj$content,
config = dash_config
)

# update reactiveVals
original_manifest(prepped_manifest)
admin_manifest(prepped_manifest)

dash_config_react(dash_config)

# FILTER MANIFEST FOR DASH ###############################################

filtered_manifest <- dfamodules::mod_datatable_filters_server(
"datatable_filters_1",
original_manifest
)

# DATASET DASH ###########################################################

dfamodules::mod_datatable_dashboard_server(
"dashboard_1",
filtered_manifest,
dash_config_react
)

# DATASET DASH VIZ : DISTRIBUTIONS ########################################

dfamodules::mod_distribution_server(
id = "distribution_contributor",
df = filtered_manifest,
Expand All @@ -165,7 +184,7 @@ app_server <- function( input, output, session ) {
y_lab = "Number of Datasets",
fill = "#0d1c38"
)

dfamodules::mod_distribution_server(
id = "distribution_datatype",
df = filtered_manifest,
Expand All @@ -175,7 +194,7 @@ app_server <- function( input, output, session ) {
y_lab = "Number of Datasets",
fill = "#0d1c38"
)

# hide waiter
waiter::waiter_hide()

Expand Down Expand Up @@ -212,7 +231,9 @@ app_server <- function( input, output, session ) {

# COLLECT WIDGET SELECTIONS ################################################

mod_administrator_widgets_out <- dfamodules::mod_administrator_widgets_server("update_data_flow_status_1")
mod_administrator_widgets_out <- dfamodules::mod_administrator_widgets_server(
id = "update_data_flow_status_1"
)

# MAKE UPDATES TO MANIFEST #################################################

Expand All @@ -232,10 +253,10 @@ app_server <- function( input, output, session ) {
})

dfamodules::mod_manifest_preview_server(
"highlight_datatable_1",
updated_manifest,
selected_rows,
"dataset_id"
id = "highlight_datatable_1",
df = updated_manifest,
selection = selected_rows,
df_match_colname = "dataset_id"
)

# BUTTON CLICK ACTIONS #####################################################
Expand All @@ -260,8 +281,9 @@ app_server <- function( input, output, session ) {
req(updated_manifest())

dfamodules::prep_manifest_submit(
updated_manifest(),
dash_config_react()
manifest = updated_manifest(),
config = dash_config_react(),
na_replace = ""
)
})

Expand Down
3 changes: 1 addition & 2 deletions R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ app_ui <- function() {
tabName = "tab_select_dcc",
shiny::fluidRow(
dfamodules::mod_select_dcc_ui(
"select_dcc",
dcc_config
"select_dcc"
)
)
),
Expand Down
10 changes: 3 additions & 7 deletions R/global.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# READ IN CONFIG
dcc_config <- Sys.getenv("DFA_DCC_CONFIG")
if (is.null(dcc_config) || nchar(dcc_config) == 0) stop("missing DFA_DCC_CONFIG environmental variable")

dcc_config <- readr::read_csv(dcc_config,
show_col_types = FALSE)
# READ IN TENANTS.JSON
tenants_config_path <- Sys.getenv("DFA_DCC_CONFIG")
if (is.null(tenants_config_path) || nchar(tenants_config_path) == 0) stop("missing DFA_DCC_CONFIG environmental variable")

# GET SCHEMATIC API URL
schematic_api_url <- Sys.getenv("DFA_SCHEMATIC_API_URL")
message("DFA is using ", schematic_api_url)

# SET UP OAUTH

client_id <- Sys.getenv("DFA_CLIENT_ID")
client_secret <- Sys.getenv("DFA_CLIENT_SECRET")
app_url <- Sys.getenv("DFA_APP_URL")
Expand Down
33 changes: 20 additions & 13 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@
},
"dfamodules": {
"Package": "dfamodules",
"Version": "23.12.1",
"Version": "24.2.1",
"Source": "GitHub",
"RemoteType": "github",
"RemoteHost": "api.github.com",
"RemoteUsername": "Sage-Bionetworks",
"RemoteRepo": "dfamodules",
"RemoteRef": "main",
"RemoteSha": "186060a0107db12255b1c65275e9dfc3e77be53e",
"RemoteRef": "dev",
"RemoteSha": "b195b41b40453b98bbc09ae81cf21155fb2a6745",
"Requirements": [
"DT",
"dplyr",
Expand All @@ -442,7 +442,7 @@
"shinyjs",
"waiter"
],
"Hash": "05924f504f548e7b17adb4bb6fce1c37"
"Hash": "8e16a925b17b61a27fc8c3ae2273c669"
},
"diffobj": {
"Package": "diffobj",
Expand Down Expand Up @@ -492,9 +492,9 @@
},
"dplyr": {
"Package": "dplyr",
"Version": "1.1.3",
"Version": "1.1.4",
"Source": "Repository",
"Repository": "CRAN",
"Repository": "RSPM",
"Requirements": [
"R",
"R6",
Expand All @@ -511,7 +511,7 @@
"utils",
"vctrs"
],
"Hash": "e85ffbebaad5f70e1a2e2ef4302b4949"
"Hash": "fedd9d00c2944ff00a0e2696ccf048ec"
},
"ellipsis": {
"Package": "ellipsis",
Expand Down Expand Up @@ -888,13 +888,13 @@
},
"jsonlite": {
"Package": "jsonlite",
"Version": "1.8.7",
"Version": "1.8.8",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"methods"
],
"Hash": "266a20443ca13c65688b2116d5220f76"
"Hash": "e1b9c55281c5adc4dd113652d9e26768"
},
"knitr": {
"Package": "knitr",
Expand Down Expand Up @@ -1627,7 +1627,14 @@
"RemoteUsername": "dreamRs",
"RemoteRepo": "shinypop",
"RemoteRef": "master",
"RemoteSha": "7745a0b1ecf31f783fa59603f3c5cede0c948118"
"RemoteSha": "7745a0b1ecf31f783fa59603f3c5cede0c948118",
"Requirements": [
"R",
"htmltools",
"jsonlite",
"shiny"
],
"Hash": "ee29555190ce6a726046a5909cc91d9b"
},
"sourcetools": {
"Package": "sourcetools",
Expand Down Expand Up @@ -1866,17 +1873,17 @@
},
"vctrs": {
"Package": "vctrs",
"Version": "0.6.2",
"Version": "0.6.5",
"Source": "Repository",
"Repository": "CRAN",
"Repository": "RSPM",
"Requirements": [
"R",
"cli",
"glue",
"lifecycle",
"rlang"
],
"Hash": "a745bda7aff4734c17294bb41d4e4607"
"Hash": "c03fa420630029418f7e6da3667aac4a"
},
"viridisLite": {
"Package": "viridisLite",
Expand Down

0 comments on commit 889fdde

Please sign in to comment.