use*_*940 6 html css r xtable shiny
我正在尝试使用xtable在html中创建一个表,但我需要在特定td标记中添加一个类,因为我要做一个动画.问题是没有xtable我不能这样做,因为它太慢了.
可能我需要用xtable表示这个.
myRenderTable<-function(){
table = "<table>"
for(i in 1:4862){
table = paste(table,"<tr><td>",i,"</td>",sep="")
for(j in 1:5){
if(j == 5){
table = paste(table,"<td class ='something'>",i+j,"</td>",sep="")
}
else{
table = paste(table,"<td>",i+j,"</td>",sep="")
}
}
table = paste(table,"</tr><table>")
}
return(table)
}
Run Code Online (Sandbox Code Playgroud)
如果我使用xtable执行此操作,我的应用程序需要15秒,但如果我使用myRederTable函数执行此操作我的应用程序需要2分钟,那么我该如何将此类放在td带有xtable的应用程序中.
我和R一起工作并且很有光泽.
问题是您正在增长一个字符串:每次追加到它时,都必须将其复制到新的内存位置。首先将数据构建为数组,然后再将其转换为 HTML 会更快。
# Sample data
n <- 4862
d <- matrix(
as.vector( outer( 0:5, 1:n, `+` ) ),
nr = 10, nc = 6*n, byrow=TRUE
)
html_class <- ifelse( col(d) %% 6 == 0, " class='something'", "" )
# The <td>...</td> blocks
html <- paste( "<td", html_class, ">", d, "</td>", sep="" )
html <- matrix(html, nr=nrow(d), nc=ncol(d))
# The rows
html <- apply( html, 1, paste, collapse = " " )
html <- paste( "<tr>", html, "</tr>" )
# The table
html <- paste( html, collapse = "\n" )
html <- paste( "<table>", html, "</table>", sep="\n" )
Run Code Online (Sandbox Code Playgroud)