Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

r shiny table not rendering html

Tags:

r

shiny

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.

like image 691
JayCo Avatar asked Sep 26 '13 04:09

JayCo


1 Answers

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.

like image 87
JayCo Avatar answered Nov 15 '22 12:11

JayCo