0

I used this link to color cells in a table: R shiny color dataframe

I've tried to change this code to allow for locking the first column in a table as the user scrolls from left to right, but haven't been able to figure it out.

Can anyone help on this?

colortable <- function(htmltab, css, style="table-condensed table-bordered"){
  tmp <- str_split(htmltab, "\n")[[1]] 
  CSSid <- gsub("\\{.+", "", css)
  CSSid <- gsub("^[\\s+]|\\s+$", "", CSSid)
  CSSidPaste <- gsub("#", "", CSSid)
  CSSid2 <- paste(" ", CSSid, sep = "")
  ids <- paste0("<td id='", CSSidPaste, "'")
  for (i in 1:length(CSSid)) {
    locations <- grep(CSSid[i], tmp)
    tmp[locations] <- gsub("<td", ids[i], tmp[locations])
    tmp[locations] <- gsub(CSSid2[i], "", tmp[locations], 
                           fixed = TRUE)
  }

tmp[1] = "<table class=\"display responsive no-wrap\" width=\"100%\" cellspacing=\"0\" cellpadding =\"0\">"   


  htmltab <- paste(tmp, collapse="\n")
  Encoding(htmltab) <- "UTF-8"
  list(
    tags$style(type="text/css", paste(css, collapse="\n")),
    tags$script(sprintf( 
      '$( "table" ).addClass( "table %s" );', style
    )),
    HTML(htmltab)
  )
}
Community
  • 1
  • 1
  • 1
    How have you changed the code? In what specific way is it not working? Please edit your question to provide more information about the issue and actual code that you're having a problem with. – Syon Aug 11 '14 at 15:02
  • I simply added this line of code after the for loop: tmp[1] = ""
    – user3930006 Aug 11 '14 at 21:24

0 Answers0