R有光泽的表格不呈现html [英] r shiny table not rendering html
本文介绍了R有光泽的表格不呈现html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用renderTable创建表,但表中的HTML未呈现:
这是感兴趣的代码片段:
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)
}
既不是HTML
、paste
或c
工作。
如何才能显示箭头?
谢谢!
server.r
:[注意,这是一个示例。代码不完整、方括号可能不匹配等。对问题不重要。]
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
只是对tableOutput
或htmlOutput
的简单调用,但这两个调用都不会呈现粘贴到列中的html。
推荐答案
此问题已通过sanitize.text.function = function(x) x
修复;
需要包含如下内容:
output$example <- renderTable({
table <- someTable_Data_here
table
}, sanitize.text.function = function(x) x)
这是要点here
另请注意,
我注意到您可以在renderTable
函数内部调用xtable
,它将正确呈现表格。
但是您应该注意,您传递给xtable
的选项没有任何效果!相反,您需要将这些选项传递给"renderTable"函数。
因此,如果您想将其称为:
output$example <- renderTable({
table <- someTable_Data_here
xtable(table, align=c("llr"))
}, sanitize.text.function = function(x) x)
您需要做的是:
output$example <- renderTable({
table <- someTable_Data_here
table
},align=c("llr"), sanitize.text.function = function(x) x)
RStudio团队和RShiny团队都很棒。我相信仍有大量的文档在编写中,我希望这会同时对某些人有所帮助。
这篇关于R有光泽的表格不呈现html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文