I'm trying to add a superscript to a DataTables footer in a Shiny app (similar as here to the rownames/body).
library(shiny)
library(DT)
ui <- fluidPage(dataTableOutput("table"))
server <- function(input, output) {
output$table <- renderDataTable({
sketch <- htmltools::withTags(table(
tableFooter(c(("Footer<sup>1</sup>"),
"Footer<sup>2</sup>"))
))
data <- datatable(data.frame(c(1, 2),
row.names = c("A<sub>1</sub>",
"A<sub>2</sub>")),
rownames = TRUE,
container = sketch,
escape = FALSE)
})
}
shinyApp(ui = ui, server = server)
However, instead of rendering to supscript, the tag is printed literally:
Having a look at sketch
shows that the greater/lesser than symbols are converted into their HTML character entities:
> sketch
<table>
<tfoot>
<tr>
<th>Footer<sup>1</sup></th>
<th>Footer<sup>2</sup></th>
</tr>
</tfoot>
</table>
I unsuccessfully tried to escape them with \
and \\
and htmltool's manual on withTags()
is quite sparse.
So, how is it possible to escape the greater/lesser signs to preserve them as tags?
Thank you already! :)
It would be best to use the additional escape
argument in the tableFooter
function.
library(shiny)
library(DT)
ui <- fluidPage(dataTableOutput("table"))
server <- function(input, output) {
output$table <- renderDataTable({
sketch <- htmltools::withTags(
table(
tableFooter(c(
"Footer<sup>1</sup>",
"Footer<sup>2</sup>"
), escape = FALSE)
)
)
data <- datatable(
data.frame(c(1, 2),
row.names = c(
"A<sub>1</sub>",
"A<sub>2</sub>"
)
),
rownames = TRUE,
container = sketch,
escape = FALSE
)
})
}
shinyApp(ui = ui, server = server)