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

前端 未结 1 1874
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-28 23:27

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

librar         


        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 00:14

    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("A1", "A2")), 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("A1", "A1"))}, rownames = T, sanitize.text.function = function(x) x)}
    
        shinyApp(ui = ui, server = server)
    

    The output table will look as follows:

    Hope it helps!

    0 讨论(0)
提交回复
热议问题