Home > Back-end >  Can I get HTML column titles within a data.frame/renderTable?
Can I get HTML column titles within a data.frame/renderTable?

Time:07-29

I am using the renderTable(data.frame('x'=1)) syntax to produce a nice interactive table, but I can't make the column names render as HTML.

Full MWE:

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

server <- function(input, output) {
  output$value <- renderUI(
      renderTable(data.frame('want_html_<sub>here</sub>'=1:3))
      )
    }

shinyApp(ui = ui, server = server)

I've tried wrapping the 'want_hmtl_here' string in HTML().

Is rendering HTML possible with this setup or do I need to use a full htmlTable like in: Display reactive htmlTable table in Shiny?

CodePudding user response:

library(shiny)

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

server <- function(input, output) {
  output$value <- renderTable({
    data.frame('want_html_<sub>here</sub>' = 1:3, check.names = FALSE)
  }, sanitize.colnames.function = function(x) x)
}

shinyApp(ui = ui, server = server)
  • Related