HTML table not rendering when escape is applied to DT table as FALSE

Hi all,

When the application runs, the first column ("plus_column") is showing as HTML tags only inside of plus button. I also tried with escape = F but did not work. Can anyone help me here

library(shiny)
library(DT)
library(tidyverse)
library(shinyjs)
add_collapse_content <- function(x, id) {
  tagList(
    tags$button(
      "data-toggle" = "collapse",
      "data-target" = paste0("#", id),
      "+"
    ),
    div(
      "id" = id,
      "class" = "collapse",
      x
    )
  )
}

ui <- fluidPage(
  DTOutput("table"),
  HTML("<head><body><div style=\"background-color:#cbe6ef; padding: .5em;text-align:center;\"><table type='text/javascript'><tr><td><b>Tag</b></td><td><b>Number of Reviews</b></td><td><b> Share of Reviews </b></td><td><b> Click for Reviews </b></td> <tr><td> null </td><td>' + d[50] + '</td><td>' + d[51] + '</td><td>' + d[52] + '</td></tr> <tr><td>' + d[45] + '</td><td>' + d[46] + '</td><td>' + d[47] + '</td><td>' + d[48] + '</td></tr></td></tr> </tr></table><script> document.querySelectorAll('td').forEach((item) => {if (item.textContent.includes('null')) {item.parentElement.remove();}});</script></body></div></body></head>")
)

server <- function(input, output, session) {
  
  useShinyjs()
  output$table <- renderDT({
    pciris <-
      iris %>%
      mutate(rn = row_number()) %>%
      rowwise() %>%
      mutate(
        plus_column =
          add_collapse_content(HTML("<head><body><div style=\"background-color:#cbe6ef; padding: .5em;text-align:center;\"><table type='text/javascript'><tr><td><b>Tag</b></td><td><b>Number of Reviews</b></td><td><b> Share of Reviews </b></td><td><b> Click for Reviews </b></td> <tr><td> null </td><td>' + d[50] + '</td><td>' + d[51] + '</td><td>' + d[52] + '</td></tr> <tr><td>' + d[45] + '</td><td>' + d[46] + '</td><td>' + d[47] + '</td><td>' + d[48] + '</td></tr></td></tr> </tr></table><script> document.querySelectorAll('td').forEach((item) => {if (item.textContent.includes('null')) {item.parentElement.remove();}});</script></body></div></body></head>"),
                               id = paste0("pc_", rn)
          ) %>%
          as.character()
      ) %>%
      relocate(plus_column)
    
    # print(head(pciris))
    # write.csv(pciris, "pciris.csv")
    datatable(pciris,
              # escape = FALSE,
              rownames = F, options = list(columnDefs = list(
                list(orderable = FALSE, className = "details-control", targets = c(0))
              ))
    )
  })
}

shinyApp(ui, server)

This topic was automatically closed 54 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.