I am trying to dynamically create and loop through htmlwidgets
such as DT
, plotly
, or rbokeh
to generate an automated knitr report. Is there a way to add knitr
formatting, such as the tabset
, into the tagList
approach outlined in this github question https://github.com/ramnathv/htmlwidgets/pull/110? I have also posted this question there.
Below is some example code of what I am thinking, but it does not quite work. What I am trying to do is create 10 tabs, each with a copy of the plot generated from plot_list
. What happens right now is all of the plots go into the last tab. In practice, plot_list
would have different plots/tables.
#' ---
#' title: htmltools::tagList test
#' output:
#' html_document
#' ---
#' # {.tabset}
#+ results='asis', echo=FALSE
library(plotly)
library(printr)
plot_list = lapply(1:10,
function(i){
as.widget(plot_ly(iris,
x = iris[["Sepal.Length"]],
y = iris[["Sepal.Width"]],
mode = "markers"))
}
)
htmltools::tagList( lapply(1:10,
function(i) {
pandoc.header(paste0("Tab",i,' {.tabset}'), 2)
plot_list[[i]]
}
)
)
# rmarkdown::render("your_path/htmltoolsTagList_test.r")
Before, I was successfully doing something like this with nested for-loops, but once I tried using figures with HTML dependencies, the figures of course do not render as they are no longer top level expressions. Is it possible in knitr
to loop like this?
A follow up question I have is: suppose I wanted to nest these tabs into another set of tabs created the same way, is that possible? What I mean to ask is, can I nest tabs dynamically using a method like this, analogous to a nested for-loop?
I am still learning how to use knitr
, and would appreciate any help!
Thank you!