DataTable in Shiny App not displaying Icons in Each Row

Can anyone please tell me why the icons arent displaying in the rendered data table? All I can see is the code as opposed to one Trash Icon in the remove column for each of the rows in my table

It's worked fine for me on previous Shiny Apps - but when starting again for a new project I cant work out what's different.

Thanks!

library(dplyr)
library(data.table)
library(dplyr)
library(DT)


values <- data.table(a = c(1,2,3),b = c(4,5,6))

ui <- fluidPage(
  DT::dataTableOutput('TabBU')
)

server <- function(input, output,session) {
  
  shinyInput <- function(FUN, n, id, ses, ...) {
    as.character(FUN(paste0(id, n), ...))
  }
  
  getRemoveButton <- function(n, idS = "", lab = "Pit") {
    if (stringr::str_length(idS) > 0) idS <- paste0(idS, "-")
    ret <- shinyInput(actionButton, n,
                      'button_', label = "Remove",icon = icon("trash-alt"),
                      onclick = sprintf('Shiny.onInputChange(\"%sremove_button_%s\",  this.id)' ,idS, lab))
    return (ret)
  }
  
  
  
  
  values = values %>%
    mutate(id = 1:nrow(values)) 
  
  values = values %>%
    rowwise() %>%
    mutate(Remove = getRemoveButton(id, idS = "", lab = "Tab1")) 
  
  output$TabBU <- renderDT(values)
  
}





shinyApp(ui, server)

https://rstudio.github.io/DT/

2.10 Escaping Table Content

The argument escape determines whether the HTML entities in the table are escaped or not. There can be potential security problems when the table is rendered in dynamic web applications such as Shiny if you do not escape them.

therefore in your code changing

to

  output$TabBU <- renderDT(
    datatable(values,
              escape = FALSE))

image

1 Like

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