问题
I have a datatable in a shiny app, in which I want to add superscript to my observations. These should detail whether the observation is an estimate, and how far the year of the observation is from the reference year (this data is already in my dataset). For example a particular observation might display : "75(superscript)-3 e".
Is this possible?
回答1:
I had the same question today and this post helped me get some of the way there. There is a working example of this on How to add subscripts in the row names of a renderTable (Shiny)? which I have pasted below, with the full acknowledgement that it's not mine!
As follows:
library(shiny)
library(DT)
ui <- fluidPage(dataTableOutput("table"))
server <- function(input, output) {
output$table <- renderDataTable({
data <- datatable(data.frame(c(1, 2), row.names = c("A<sub>1</sub>", "A<sub>2</sub>")), rownames = T, escape = FALSE)
})
}
shinyApp(ui = ui, server = server)
I have tried similar <sub>
and <sup>
tags in the body of the table and it treats it in the same way.
回答2:
Ok the solution is to input the superscript within html tags and specify "escape = FALSE" within render datatable in order to render the html.
来源:https://stackoverflow.com/questions/45537398/render-sub-superscript-in-table-shiny