Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
^.*\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^_pkgdown\.yml$
^docs$
^pkgdown$
^vignettes/articles$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
inst/doc
docs
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ Imports:
openxlsx,
ospsuite.utils (>= 1.7.0),
readxl
Remotes:
Remotes:
ospsuite=Open-Systems-Pharmacology/OSPSuite-R@*release,
ospsuite.utils=Open-Systems-Pharmacology/OSPSuite.RUtils@*release
Suggests:
devtools,
gt,
knitr,
rmarkdown,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
tidyxl
Config/testthat/edition: 3
VignetteBuilder: knitr
Depends:
R (>= 4.1.0)
Config/Needs/website: rmarkdown
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: https://www.open-systems-pharmacology.org/OSPSuite.QualificationPlanEditor/
template:
bootstrap: 5

74 changes: 74 additions & 0 deletions inst/excel-display.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#' @title displayExcel
#' @description
#' A function that displays an Excel file with its styling
#' for pkgdown html format using `gt` and `tidyxl` packages
#' @param excelFile path of Excel file
#' @param level Section level for the displayed tab
#' @return Character string
displayExcel <- function(excelFile, level = 2) {
htmlContent <- paste(
paste0(rep("#", level), collapse = ""),
"Excel Content {.tabset .tabset-pills} \n\n"
)

excelSheets <- readxl::excel_sheets(excelFile)
excelFormats <- tidyxl::xlsx_formats(excelFile)
excelCells <- tidyxl::xlsx_cells(excelFile)
for (excelSheet in excelSheets) {
excelData <- openxlsx::readWorkbook(xlsxFile = excelFile, sheet = excelSheet, check.names = FALSE)
# Select content for the specific Excel sheet
dataCells <- excelCells |>
dplyr::filter(.data[["sheet"]] %in% excelSheet) |>
dplyr::filter(.data[["col"]] == 1)
# Create a list define font and background styles for each row
dataStyles <- data.frame(
row = dataCells$row - 1,
color = excelFormats$local$font$color$rgb[dataCells$local_format_id],
fill = excelFormats$local$fill$patternFill$fgColor$rgb[dataCells$local_format_id]
) |>
dplyr::mutate(
color = paste0("#", substr(.data[["color"]], 3, nchar(.data[["color"]]))),
fill = paste0("#", substr(.data[["fill"]], 3, nchar(.data[["fill"]]))),
color = ifelse(.data[["color"]] %in% "#NA", "#000000", .data[["color"]]),
fill = ifelse(.data[["fill"]] %in% "#NA", "#ffffff", .data[["fill"]])
)
dataStyles <- split(tail(dataStyles, -1), 1:(nrow(dataStyles) - 1))
excelTable <- styleExcelData(excelData, dataStyles)

htmlContent <- c(
htmlContent,
paste(
paste0(rep("#", level + 1), collapse = ""),
excelSheet,
"\n\n",
gt::as_raw_html(excelTable),
"\n\n"
)
)
}
return(htmlContent)
}

#' @title dataWithStyle
#' @description
#' A function to apply Excel styles in each row of a data.frame
#' @param data A data.frame
#' @param styles A list of `color`, `fill` styles mapped to a `row`
#' @return A `gt` table
styleExcelData <- function(data, styles) {
gtTable <- gt::gt(data)
if(nrow(data)==0){
return(gtTable)
}
for (style in styles) {
gtTable <- gtTable |>
gt::tab_style(
style = list(
gt::cell_fill(color = style$fill),
gt::cell_text(color = style$color)
),
locations = gt::cells_body(rows = style$row)
)
}
return(gtTable)
}
2 changes: 2 additions & 0 deletions vignettes/articles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.R
Loading
Loading