inst/text/shiny/core_functions.R

####################### Core functions #######################

# Add n linebreaks
linebreaks <- function(n) {
  HTML(strrep(br(), n))
}

# Remove warnings from icons
icon_no_warning_fn = function(icon_name) {
  icon(icon_name, verify_fa = FALSE)
}

# Generic data table
make_table <- function(input_data_table, rows_to_display = 20) {
  # Take out underscores in column names for display purposes
  table_colnames <- gsub("_", " ", colnames(input_data_table))

  dt <- DT::datatable(
    input_data_table,
    style = 'bootstrap',
    class = 'table-bordered table-condensed',
    rownames = FALSE,
    filter = "top",
    colnames = table_colnames,
    options = list(
      pageLength = rows_to_display,
      scrollX = FALSE,
      scrollY = FALSE,
      dom = 'tip',
      autoWidth = TRUE,
      # style header
      initComplete = htmlwidgets::JS(
        "function(settings, json) {",
        "$(this.api().table().header()).css({'background-color': '#C5C3DA', 'color': '#3F3685'});",
        "$(this.api().table().row().index()).css({'background-color': '#C5C3DA', 'color': '#3F3685'});",
        "}"
      )
    )
  )

  return(dt)
}
Health-SocialCare-Scotland/phstemplates documentation built on June 13, 2025, 2:51 p.m.