I want to display a html-table in a shiny page. The table is generated by a function and uses the following data:
rep_loop <- data.frame(Activity = LETTERS[1:3], ID_resource_rep = sample(1:10, 3),
Div_resource_rep = sample(1:10, 3),
ID_resource_loop = sample(1:10, 3),
Div_resource_loop = sample(1:10, 3))
build_table <- function(data){
html.table <-
tags$table(style = "border:1px solid black; padding: 3%; width: 80%",
tags$tr(
tags$th(" "),
tags$th(colspan = 2, "Repeat (Act-X-Act)"),
tags$th(colspan = 2, "Selfloop (Act-Act)")
),
tags$tr(
tags$th(" "),
tags$th("Same Resource"),
tags$th("Other Resource"),
tags$th("Same Resource"),
tags$th("Other Resource")
),
tags$tr(
tags$td(data$Activity),
tags$td(data$ID_resource_rep),
tags$td(data$Div_resource_rep),
tags$td(data$ID_resource_loop),
tags$td(data$Div_resource_loop)
)
)
return(html.table)
}
This is the result from
test <- build_table(rep_loop)
<table style="border:1px solid black; padding: 5%; width: 80%">
<tr>
<th> </th>
<th colspan="2">Repeat (Act-X-Act)</th>
<th colspan="2">Selfloop (Act-Act)</th>
</tr>
<tr>
<th> </th>
<th>Same Resource</th>
<th>Other Resource</th>
<th>Same Resource</th>
<th>Other Resource</th>
</tr>
<tr>
<td>A</td>
<td>1</td>
<td>1</td>
<td>4</td>
<td>6</td>
</tr>
</table>
Warning messages:
1: In charToRaw(enc2utf8(text)) :
argument should be a character vector of length 1
all but the first element will be ignored
2: In charToRaw(enc2utf8(text)) :
argument should be a character vector of length 1
all but the first element will be ignored
3: In charToRaw(enc2utf8(text)) :
argument should be a character vector of length 1
all but the first element will be ignored
4: In charToRaw(enc2utf8(text)) :
argument should be a character vector of length 1
all but the first element will be ignored
5: In charToRaw(enc2utf8(text)) :
argument should be a character vector of length 1
all but the first element will be ignored
I would expect that build_table would return a table with a header, followed by data-lines. The header is as expected but instead of using all the rows from the data.frame, it shows only the first line, followed by 5 warnings.
Where did I make a mistake?
Ben