зеркало из https://github.com/microsoft/wpa.git
feat: generate_report2
Add function which enables generating HTML reports directly from an existing RMarkdown document / template.
This commit is contained in:
Родитель
c5fe661565
Коммит
abedb5b90f
|
@ -74,6 +74,7 @@ export(flag_outlooktime)
|
|||
export(flex_index)
|
||||
export(g2g_network)
|
||||
export(generate_report)
|
||||
export(generate_report2)
|
||||
export(heat_colors)
|
||||
export(heat_colours)
|
||||
export(hr_trend)
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
|
||||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
#' @title Generate HTML report based on existing RMarkdown documents
|
||||
#'
|
||||
#' @description
|
||||
#' This is a support function that accepts parameters and creates a HTML
|
||||
#' document based on an RMarkdown template. This is an alternative to
|
||||
#' `generate_report()` which instead creates an RMarkdown document from scratch
|
||||
#' using individual code chunks.
|
||||
#'
|
||||
#' @note
|
||||
#' The implementation of this function was inspired by the 'DataExplorer'
|
||||
#' package by boxuancui, with credits due to the original author.
|
||||
#'
|
||||
#' @param output_format output format in `rmarkdown::render()`. Default is
|
||||
#' `rmarkdown::html_document(toc = TRUE, toc_depth = 6, theme = "cosmo")`.
|
||||
#' @param output_file output file name in `rmarkdown::render()`. Default is
|
||||
#' `"report.html"`.
|
||||
#' @param output_dir output directory for report in `rmarkdown::render()`.
|
||||
#' Default is user's current directory.
|
||||
#' @param report_title report title. Default is `"Report"`.
|
||||
#' @param \dots other arguments to be passed to `params`. For instance, pass
|
||||
#' `hrvar` if the RMarkdown document requires a 'hrvar' parameter.
|
||||
#' @export
|
||||
|
||||
generate_report2 <- function(output_format = rmarkdown::html_document(toc = TRUE, toc_depth = 6, theme = "cosmo"),
|
||||
output_file = "report.html",
|
||||
output_dir = getwd(),
|
||||
report_title = "Report",
|
||||
rmd_dir = system.file("rmd_template/minimal.rmd", package = "wpa"),
|
||||
...) {
|
||||
|
||||
## Render report into html
|
||||
suppressWarnings(
|
||||
rmarkdown::render(
|
||||
input = rmd_dir,
|
||||
output_format = output_format,
|
||||
output_file = output_file,
|
||||
output_dir = output_dir,
|
||||
intermediates_dir = output_dir,
|
||||
params = list(data = data,
|
||||
set_title = report_title,
|
||||
...)
|
||||
))
|
||||
|
||||
## Open report
|
||||
report_path <- path.expand(file.path(output_dir, output_file))
|
||||
utils::browseURL(report_path)
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
params:
|
||||
data: data
|
||||
set_title: report_title
|
||||
hrvar: hrvar
|
||||
mingroup: mingroup
|
||||
title: "`r params$set_title`"
|
||||
---
|
||||
|
||||
# Minimal Report
|
||||
|
||||
This is a minimal report that shows basic diagnostic information about the dataset. This report is designed for testing purposes only.
|
||||
|
||||
```{r echo=FALSE, message=FALSE, warning=FALSE}
|
||||
library(wpa)
|
||||
|
||||
## Get user data
|
||||
data <- params$data
|
||||
hrvar <- params$hrvar
|
||||
mingroup <- params$mingroup
|
||||
|
||||
keymetrics_scan(data,
|
||||
hrvar = hrvar,
|
||||
mingroup = mingroup)
|
||||
```
|
||||
|
||||
|
||||
## Email Hours
|
||||
|
||||
Here is a view of email hours.
|
||||
|
||||
```{r echo=FALSE}
|
||||
create_bar(data,
|
||||
hrvar = hrvar,
|
||||
metric = "Email_hours",
|
||||
mingroup = mingroup)
|
||||
```
|
||||
|
||||
|
||||
## Diagnostics
|
||||
|
||||
```{r echo=FALSE}
|
||||
check_query(data)
|
||||
```
|
|
@ -0,0 +1,40 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/generate_report2.R
|
||||
\name{generate_report2}
|
||||
\alias{generate_report2}
|
||||
\title{Generate HTML report based on existing RMarkdown documents}
|
||||
\usage{
|
||||
generate_report2(
|
||||
output_format = rmarkdown::html_document(toc = TRUE, toc_depth = 6, theme = "cosmo"),
|
||||
output_file = "report.html",
|
||||
output_dir = getwd(),
|
||||
report_title = "Report",
|
||||
rmd_dir = system.file("rmd_template/minimal.rmd", package = "wpa"),
|
||||
...
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{output_format}{output format in \code{rmarkdown::render()}. Default is
|
||||
\code{rmarkdown::html_document(toc = TRUE, toc_depth = 6, theme = "cosmo")}.}
|
||||
|
||||
\item{output_file}{output file name in \code{rmarkdown::render()}. Default is
|
||||
\code{"report.html"}.}
|
||||
|
||||
\item{output_dir}{output directory for report in \code{rmarkdown::render()}.
|
||||
Default is user's current directory.}
|
||||
|
||||
\item{report_title}{report title. Default is \code{"Report"}.}
|
||||
|
||||
\item{\dots}{other arguments to be passed to \code{params}. For instance, pass
|
||||
\code{hrvar} if the RMarkdown document requires a 'hrvar' parameter.}
|
||||
}
|
||||
\description{
|
||||
This is a support function that accepts parameters and creates a HTML
|
||||
document based on an RMarkdown template. This is an alternative to
|
||||
\code{generate_report()} which instead creates an RMarkdown document from scratch
|
||||
using individual code chunks.
|
||||
}
|
||||
\note{
|
||||
The implementation of this function was inspired by the 'DataExplorer'
|
||||
package by boxuancui, with credits due to the original author.
|
||||
}
|
Загрузка…
Ссылка в новой задаче