mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-21 05:59:07 +02:00
major overhaul with new functions. docs are lacking
This commit is contained in:
parent
1fd3911974
commit
04f5bec85c
28 changed files with 874 additions and 81 deletions
68
R/html_styling.R
Normal file
68
R/html_styling.R
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#' Create two-column HTML table for data piping in REDCap instruments
|
||||
#'
|
||||
#' @param text descriptive text
|
||||
#' @param variable variable to pipe
|
||||
#'
|
||||
#' @return character vector
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' create_html_table(text = "Patient ID", variable = c("[cpr]"))
|
||||
#' create_html_table(text = paste("assessor", 1:2, sep = "_"), variable = c("[cpr]"))
|
||||
#' # create_html_table(text = c("CPR nummer","Word"), variable = c("[cpr][1]", "[cpr][2]", "[test]"))
|
||||
create_html_table <- function(text, variable) {
|
||||
assertthat::assert_that(length(text)>1 & length(variable)==1 |
|
||||
length(text)==1 & length(variable)>1 |
|
||||
length(text)==length(variable),
|
||||
msg = "text and variable has to have same length, or one has to have length 1")
|
||||
|
||||
start <- '<table style="border-collapse: collapse; width: 100%;" border="0"> <tbody>'
|
||||
end <- "</tbody> </table>"
|
||||
|
||||
# Extension would allow defining number of columns and specify styling
|
||||
items <- purrr::map2(text, variable, function(.x, .y) {
|
||||
glue::glue('<tr> <td style="width: 58%;"> <h5><span style="font-weight: normal;">{.x}<br /></span></h5> </td> <td style="width: 42%; text-align: left;"> <h5><span style="font-weight: bold;">{.y}</span></h5> </td> </tr>')
|
||||
})
|
||||
|
||||
glue::glue(start, glue::glue_collapse(purrr::list_c(items)), end)
|
||||
}
|
||||
|
||||
#' Simple html tag wrapping for REDCap text formatting
|
||||
#'
|
||||
#' @param data character vector
|
||||
#' @param tag character vector length 1
|
||||
#' @param extra character vector
|
||||
#'
|
||||
#' @return character vector
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' html_tag_wrap("Titel", tag = "div", extra = 'class="rich-text-field-label"')
|
||||
#' html_tag_wrap("Titel", tag = "h2")
|
||||
html_tag_wrap <- function(data, tag = "h2", extra = NULL) {
|
||||
et <- ifelse(is.null(extra), "", paste0(" ", extra))
|
||||
glue::glue("<{tag}{et}>{data}</{tag}>")
|
||||
}
|
||||
|
||||
|
||||
#' Sub-header formatting wrapper
|
||||
#'
|
||||
#' @param data character vector
|
||||
#' @param tag character vector length 1
|
||||
#'
|
||||
#' @return character vector
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' "Instrument header" |> format_subheader()
|
||||
format_subheader <- function(data, tag = "h2") {
|
||||
dplyr::if_else(is.na(data) | data == "",
|
||||
NA,
|
||||
data |>
|
||||
html_tag_wrap(tag = tag) |>
|
||||
html_tag_wrap(
|
||||
tag = "div",
|
||||
extra = 'class="rich-text-field-label"'
|
||||
)
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue