-
Notifications
You must be signed in to change notification settings - Fork 2
#27 draft documentation vignettes #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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$ | ||
pchelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| inst/doc | ||
| docs |
| 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 | ||
|
|
| 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) { | ||
pchelle marked this conversation as resolved.
Show resolved
Hide resolved
pchelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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(sheet %in% excelSheet) |> | ||
| dplyr::filter(col == 1) | ||
| # Create a list define font and background styles for each row | ||
pchelle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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(color, 3, nchar(color))), | ||
|
Check warning on line 30 in inst/excel-display.R
|
||
| fill = paste0("#", substr(fill, 3, nchar(fill))), | ||
|
Check warning on line 31 in inst/excel-display.R
|
||
| color = ifelse(color %in% "#NA", "#000000", color), | ||
| fill = ifelse(fill %in% "#NA", "#ffffff", 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 | ||
pchelle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #' @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){ | ||
pchelle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| *.html | ||
| *.R |
Uh oh!
There was an error while loading. Please reload this page.