I am trying to create some plot shapes in an Rmarkdown document using a loop or lapply.
Script R:
require(plotly) data(iris) b <- lapply(setdiff(names(iris), c("Sepal.Length","Species")), function(x) { plot_ly(iris, x = iris[["Sepal.Length"]], y = iris[[x]], mode = "markers") }) print(b)
works fine, but doesn't work if included in the knitr block:
--- output: html_document --- '''{r,results='asis'} require(plotly) data(iris) b <- lapply(setdiff(names(iris), c("Sepal.Length","Species")), function(x) { plot_ly(iris, x = iris[["Sepal.Length"]], y = iris[[x]], mode = "markers") }) print(b) '''
I tried replacing print(b) combination of lapply eval and parse but only the last digit was displayed.
I suspect the scope / environment problem, but I cannot find a solution.
source share