Icons show up as text in Datatable

I am trying to show icons in a datatable. When I try showing it inside a data table the icons show up as text. <i class="glyphicon glyphicon-ok"></i>

Do icons work with datatable.

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

df <- data.frame(Channel = c("A", "B","C"),
                 Current = c(2000, 3000, 4000),
                 Modified = c(2500, 3500,3000),
                 New_Membership = c(500, 500,-1000),
                 stringsAsFactors = FALSE)


#### Module 1 renders the first table
tableMod <- function(input, output, session, modelRun,modelData,ratesData,budget){
  
  gicon <- function(x) as.character(icon(x, lib = "glyphicon"))
  

  output$x1 <- DT::renderDataTable({
    isolate(
      datatable(
        modelData %>% mutate(myvar = Modified - Current) %>% 
        mutate(direction = ifelse(
          Current < Modified,
          as.character(gicon("ok")),
          as.character(gicon("remove")))), selection = 'none', editable = TRUE
      ) 
      )
      
  })
  
  
  
}
firstTableUI <- function(id) {
  ns <- NS(id)
  dataTableOutput(ns("x1"))
}

ui <- function(request) {
  fluidPage(
    firstTableUI("opfun"),
    numericInput("budget_input", "Total Forecast", value = 2),
    actionButton("opt_run", "Run")  )
}
server <- function(input, output, session) {
  
  callModule( tableMod,"opfun",
              modelRun = reactive(input$opt_run),
              modelData = df,
              ratesData = rates,
              budget = reactive(input$budget_input))
  
  observeEvent(input$opt_run, {
    cat('HJE')
  })
}

shinyApp(ui, server, enableBookmarking = "url")

I think you need to set escape = FALSE in the data.table call to keep html string as html.
See this chapter in the doc
https://rstudio.github.io/DT/#escaping-table-content

1 Like

Thank You @cderv. It works now.

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.