Skip to content

Commit

Permalink
added custom theme
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeya committed Sep 8, 2023
1 parent a1d97b2 commit a6d2e2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ Imports:
shiny (>= 1.6.0),
shinyWidgets (>= 0.5.1),
yaml (>= 1.1.0),
zip (>= 1.1.0)
zip (>= 1.1.0),
flextable
Suggests:
DT (>= 0.13),
ggplot2 (>= 3.4.0),
lattice (>= 0.18-4),
png,
rtables (>= 0.5.1),
testthat (>= 3.0.4),
flextable,
tinytex
VignetteBuilder:
knitr
Expand Down
17 changes: 11 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ panel_item <- function(title, ..., collapsed = TRUE, input_id = NULL) {
#'
#' @keywords internal
to_flextable <- function(content) {
if (inherits(content, c("rtables", "TableTree"))) {
if (inherits(content, c("rtables", "TableTree", "ElementaryTable"))) {
mf <- rtables::matrix_form(content)
nr_header <- attr(mf, "nrow_header")
non_total_coln <- c(TRUE, !grepl("All Patients", names(content)))
Expand All @@ -146,7 +146,6 @@ to_flextable <- function(content) {
dim(ft)$widths[1],
dim(ft)$widths[-1] - dim(ft)$widths[-1] + sum(dim(ft)$widths[-1]) / (ncol(mf$strings) - 1)
)

ft <- flextable::width(ft, width = width_vector)
} else if (inherits(content, "data.frame")) {
ft <- flextable::flextable(content)
Expand All @@ -155,10 +154,7 @@ to_flextable <- function(content) {
}

if (inherits(ft, "flextable")) {
ft <- flextable::theme_booktabs(ft)
ft <- flextable::font(ft, fontname = "arial", part = "all")
ft <- flextable::fontsize(ft, size = 8, part = "body")
ft <- flextable::bold(ft, part = "header")
ft <- custom_theme(ft)

if (inherits(ft, "flextable") && flextable::flextable_dim(ft)$widths > 10) {
pgwidth <- 10.5
Expand All @@ -170,6 +166,15 @@ to_flextable <- function(content) {
ft
}

#' @noRd
custom_theme <- function(ft) {
ft <- flextable::fontsize(ft, size = 8, part = "body")
ft <- flextable::bold(ft, part = "header")
ft <- flextable::theme_booktabs(ft)
ft <- flextable::hline(ft, border = flextable::fp_border_default(width =1, color = "grey"))
ft <- flextable::border_outer(ft)
ft
}

#' @noRd
get_merge_index_single <- function(span) {
Expand Down

0 comments on commit a6d2e2a

Please sign in to comment.