I'd like to make a Rmarkdown report, and use a function to encapsulate making of multiple grouped dygraph
charts. I cannot figure out how to have all of the charts rendered when called from within a function. The following snippet only renders only the last of the two dygraph plots I create. I am looking for how I display both plots in the ensuing markdown by calling the function foo()
.
I have an answer/response below that gets most of the way there, but I cannot figure out how to control the height/width appropriately, which is laid out there.
#' ---
#' title: "scratchRmd.R"
#' author: "Matt"
#' date: "`r Sys.Date()`"
#' output:
#' html_document:
#' toc: true
#' toc_depth: 3
#' code_folding: hide
#' editor_options:
#' chunk_output_type: console
#' ---
#+message=F,warning=F
options(width = 188)
library(xts)
library(lubridate)
library(dygraphs)
library(dplyr)
#' # Run it
#'
#+
foo <- function() {
tsv <-
seq(from=ymd("2022-01-01"), to=ymd("2022-01-08"), by="1 day")
y <-
runif(length(tsv))
z <-
runif(length(tsv))
dygraph(xts(y, order.by = tsv)
, main="Y"
, group=1)
dygraph(xts(z, order.by = tsv)
, main="Z"
, group=1)
}
foo()