Using `ggplotly` and `DT` from a `for` loop in Rmarkdown

后端 未结 2 1673
轮回少年
轮回少年 2021-01-15 00:14

Is that possible to use ggplotly() or datatable() in RMarkdown from inside a for loop or function? Example:

---
title:          


        
2条回答
  •  滥情空心
    2021-01-15 00:49

    This seems to be a persistent problem with RMarkdown. Here is the work around however, found here:

    lotlist = list()
    
    for (VAR in factor_vars) {
        p <- ggplot(mtcars, aes_string(x = "mpg", y = "wt", color = VAR)) + geom_point()
        plotlist[[VAR]] = ggplotly(p)
    }
    htmltools::tagList(setNames(plotlist, NULL))
    

提交回复
热议问题