-
Notifications
You must be signed in to change notification settings - Fork 4
/
global.R
60 lines (51 loc) · 1.78 KB
/
global.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
## Load packages
suppressPackageStartupMessages(library("dplyr"))
suppressPackageStartupMessages(library("purrr"))
suppressPackageStartupMessages(library("reactable"))
suppressPackageStartupMessages(library("shiny"))
## 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("
function(values, rows) {
joined = values.join(', ')
if (joined.length <= 20) {
return joined
}
return joined.slice(0, 20) + '...'
}
")
#' 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)
}