I am trying to create loop for building custom HTML Table. I am having issue in nested lapply.
Code
library(htmltools)
dataframe <- iris[1:5,]
tags$tbody(
apply(dataframe,1, function(x) { tags$tr(list('class = "Row"',
lapply(colnames(dataframe), function(x1) glue::glue("data-{x1}="))),
lapply(x, function(y) tags$td(y)))})
)
Desired Output
<tr class = "Row"
data-Sepal.Length=5.1
data-Sepal.Width="3.5"
data-Petal.Length="1.4"
data-Petal.Width="0.2"
data-Species= "setosa">
<td>5.1</td>
<td>3.5</td>
<td>1.4</td>
<td>0.2</td>
<td>setosa</td>
</tr>
What I am getting as of now -
<tr>
class = "Row"
data-Sepal.Length=
data-Sepal.Width=
data-Petal.Length=
data-Petal.Width=
data-Species=
<td>5.1</td>
<td>3.5</td>
<td>1.4</td>
<td>0.2</td>
<td>setosa</td>
</tr>