13

I'm creating a table using renderTable but the HTML inside the table is not rendering:

table not rendering

This is the code snipit of interest:

if (is.null(Compare_Count) || is.na(Compare_Count) || length(Compare_Count) == 0L ) {
          CT_Table[i, 3] <- HTML("<i class='icon-arrow-up'></i>")
        } else if (CT_Table[i, 2] > Compare_Count) {
          CT_Table[i, 3] <- print(tags$i(class='icon-arrow-up', style="text-color: green"), quote = FALSE)
}

Neither HTML, paste, or c work.

How can I get the arrows to show?

Thanks!


server.r: [Note, this is an example. The code is not complete, brackets may be mismatched, etc. Not important to the question.]

output$example <- renderTable(include.rownames=FALSE,{
 CT_Table <- count(Canidates,vars=c("Name"))
 CT_Table <- CT_Table[order(CT_Table["Recent Reviews: "], decreasing=T),]
    for (i in 1:nrow(CT_Table)) {
      Compare_Name <- paste(CT_Table$Product[i])
      Compare_Count <- Can_trend[Can_trend$Name == Compare_Name, 2]
        if (is.null(Compare_Count) || is.na(Compare_Count) || length(Compare_Count) == 0L ) 
{
          CT_Table[i, 3] <- HTML("<i class='icon-arrow-up'></i>")
        } else if (CT_Table[i, 2] > Compare_Count) {
          CT_Table[i, 3] <- tags$i(class='icon-arrow-up', style="text-color: green")
        } else if (CT_Table[i, 2] < Compare_Count) {
          CT_Table[i, 3] <- tags$i(class='icon-arrow-down', style="text-color: red")
        } else if (CT_Table[i, 2] == Compare_Count) {
          CT_Table[i, 3] <- tags$i(class='icon-minus', style="text-color: yellow")
        }
     }
  }
 CT_Table
})

ui.r is just a simple call to tableOutput or htmlOutput, but neither renders the html pasted into the column.

2
  • Could you provide minimal but complete ui.R and server.R files ?
    – juba
    Sep 26, 2013 at 9:28
  • I have updated the question with a more complete code example; the file is a few thousand lines long, so I'm trying to only paste in whats necessary. Please let me know if I left anything out, and thank you!
    – JayCo
    Sep 26, 2013 at 16:56

1 Answer 1

16

This was fixed with sanitize.text.function = function(x) x;

it needs to be included like this:

output$example <- renderTable({
   table <- someTable_Data_here
   table
}, sanitize.text.function = function(x) x) 

This is the gist here


also, a note,

I have noticed that you can call xtable inside the renderTable function, and it will properly render the table.

BUT you should note that options you pass to xtable have no effect! Instead you need to pass those options to the 'renderTable' function.

so if you want to call this:

output$example <- renderTable({
   table <- someTable_Data_here
   xtable(table, align=c("llr"))
}, sanitize.text.function = function(x) x) 

what you need to do is:

output$example <- renderTable({
   table <- someTable_Data_here
   table
},align=c("llr"), sanitize.text.function = function(x) x) 

The RStudio team and the RShiny guys are awesome. I'm sure a ton of the documentation is still being written, and I hope this helps someone in the mean time.

3
  • 1
    Is there an equivalent of sanitize.text.function for renderDataTable? Thanks!
    – harkmug
    Mar 7, 2014 at 21:57
  • It looks unlikely, as sanitize.text.function is from the xtable package which itself writes the html - renderTable is just passing parameters to it. It is probably possible to embed html in a way that renderDataTable will properly display it... but that sounds like a new question!
    – JayCo
    Mar 7, 2014 at 23:39
  • You don't need to use any text sensitization for renderDataTable - it renders html automatically. You should note thought that the current implementation (Nov 1st 2014) will sort your stylized html alphabetically without escaping the html! I have submitted a bug report for that.
    – JayCo
    Nov 1, 2014 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.