Skip to content

Commit

Permalink
PHS HTML template (#69)
Browse files Browse the repository at this point in the history
* PHS HTML template

* copy in CSS file with code

* Update documentation

* tidying

---------

Co-authored-by: Alan Yeung <[email protected]>
Co-authored-by: alan-y <[email protected]>
  • Loading branch information
3 people authored Nov 7, 2023
1 parent d01fe75 commit da0311d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Added three Management information templates for Word documents, accessible through RStudio menu: a Management Info Report, A Management Info Summary, and, a Management Info One Page template.
* The Management Info One Page template will accommodate using more than one page and applies page numbers from page 2 onwards, so could also be used as a template for a simple information request response.
* Basic PHS style HTML template.
* RStudio addin for `add_stylecss()` so users can add a PHS style.css file directly from RStudio.


Expand Down
9 changes: 7 additions & 2 deletions R/add_stylecss.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#'
#' @param path String: path to add phs_style.css file. If left blank, RStudio will prompt the user.
#' @param shinycss Logical: Whether to append shiny CSS code to the file (TRUE) or not (FALSE). If left blank, RStudio will prompt the user.
#' @param auto_open Logical: Automatically open the phs_style.css after it is compiled?
#'
#' @return NULL - Adds phs_style.css file to the directory.
#' @export
Expand All @@ -11,7 +12,7 @@
#' add_stylecss()
#' }
add_stylecss <- function(path = rstudioapi::selectDirectory(caption = "Select folder to add phs_style.css"),
shinycss = FALSE) {
shinycss = FALSE, auto_open = TRUE) {
if (is.null(path)) {
message("phs_style.css file not added.")
return(invisible(NULL))
Expand Down Expand Up @@ -54,6 +55,10 @@ add_stylecss <- function(path = rstudioapi::selectDirectory(caption = "Select fo

writeLines(stylecss, con = file.path(path, "phs_style.css"))
message(paste("phs_style.css has been written to", path))
rstudioapi::documentOpen(file.path(path, "phs_style.css"))

if (auto_open) {
rstudioapi::documentOpen(file.path(path, "phs_style.css"))
}

return(invisible(NULL))
}
40 changes: 40 additions & 0 deletions inst/rmarkdown/templates/phs-html/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: "My PHS HTML Document"
author: "My Name"
date: "`r format(Sys.Date(), '%d %B %Y')`"
output:
html_document:
css: phs_style.css
toc: true
toc_float: true
keep_md: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# Copy in the PHS style CSS file if required
if (!file.exists(file.path(getwd(), "phs_style.css"))) {
phstemplates::add_stylecss(getwd(), auto_open = FALSE)
}
```

# R Markdown

This is an R Markdown document with basic PHS styles included for output to HTML.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
2 changes: 2 additions & 0 deletions inst/rmarkdown/templates/phs-html/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: PHS HTML Document
description: Template to produce a PHS document with basic PHS styles.
5 changes: 4 additions & 1 deletion man/add_stylecss.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da0311d

Please sign in to comment.