[英]r shiny table not rendering 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
的簡單調用,但都不htmlOutput
html粘貼到列中。
這是用sanitize.text.function = function(x) x
修復的;
它需要像這樣包括:
output$example <- renderTable({
table <- someTable_Data_here
table
}, sanitize.text.function = function(x) x)
這是這里的要點
還有,一張便條,
我注意到你可以在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團隊非常棒。 我確信還有大量的文檔仍在編寫中,我希望這能幫到某些人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.