Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

r shiny table not rendering html

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...