Render sub/superscript in table (shiny)

2019-07-13 00:55发布

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?

2条回答
beautiful°
2楼-- · 2019-07-13 01:35

Ok the solution is to input the superscript within html tags and specify "escape = FALSE" within render datatable in order to render the html.

查看更多
甜甜的少女心
3楼-- · 2019-07-13 01:38

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.

查看更多
登录 后发表回答