Icons not shown in datatable when not using Shiny

I would like to include icons in a datatable. This works fine for Shiny, see example below, but does not work without shiny.

library(shiny)
library(DT)
library(dplyr)

ui <- basicPage(
  DT::dataTableOutput("table")
)

server <- function(input, output, session) {
  output$table <- DT::renderDataTable({
    data <- mtcars %>% 
      mutate(icon = as.character(icon("tag", lib = "glyphicon")))
    datatable(data, escape = FALSE) 
  })
}

shinyApp(ui, server)

In this example using shiny the icons are shown:

library(DT)
library(dplyr)

 data <- mtcars %>% 
      mutate(icon = as.character(icon("tag", lib = "glyphicon")))

datatable(data, escape = FALSE) 


However, without Shiny there are no icons.

Thanks to this post I was able to find a solution, although I'm completly bewildered by why it works. Wrapping datatable in both browsable and fluidpage solves the issue. This also works for icons created by formattable and using as.datatable.

If anyone cares to explain why this works I'd love to hear.

library(DT)
library(dplyr)
library(htmltools)
library(shiny)

data <- mtcars %>% 
  mutate(icon = as.character(icon("tag", lib = "glyphicon")))

browsable(fluidPage(datatable(data, escape = FALSE))) 

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.