简体   繁体   中英

How to add subscripts in the row names of a renderTable (Shiny)?

How to add subscripts in the row names of a renderTable ? In the following example I need subscripts in A_1 and A_2 .

library(shiny)

ui <- fluidPage(tableOutput("table"))

server <- function(input, output) {
  output$table <- renderTable({data <- data.frame(c(1, 2),
                                         row.names = c("A_1", "A_2"))}, rownames = T)}

shinyApp(ui = ui, server = server)

You can use DT package for datatable for that. You need to use html tags with escape = FALSE . Have a look at the modified your code below:

  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)

You get a table which looks like this:

在此处输入图片说明

EDIT:

You can add subscript for renderTable by using html tags with sanitize.text.function = function(x) x . The code would be as shown below:

 library(shiny)

    ui <- fluidPage(tableOutput("table"))

    server <- function(input, output) {
      output$table <- renderTable({data <- data.frame(c(1, 2),
                                                      row.names = c("A<sub>1</sub>", "A<sub>1</sub>"))}, rownames = T, sanitize.text.function = function(x) x)}

    shinyApp(ui = ui, server = server)

The output table will look as follows: 在此处输入图片说明

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM