我有一个构建HTML表并以字符串形式返回代码的函数。我从renderUI调用此函数并以HTML格式输出,但HTML未被解析,我只在输出中将字符串作为纯文本格式。我是否需要在函数调用中添加任何内容?
ui <- fluidPage(
fluidRow(
column(width=3),
column(width=6, htmlOutput('table')),
column(width=3)
)
)
server <- function(input, output) {
tables <- data.frame(c("exmpl1", "exmpl2"), c("abc", "def"))
output$table <- renderUI({
create.table(tables)
})
}
create.table = function(tables) {
rowCount <- c(1:nrow(tables))
htmlTbl <-
paste(
"tags$table(
tags$tr(
tags$th('Col1'),
tags$th('Col2'),
tags$th('Col3')
),"
)
for (val in rowCount) {
htmlTbl <- paste(htmlTbl,"tags$tr(
tags$td(checkboxInput('check",val,"', NULL)),
tags$td(tables[",val,", 1]),
tags$td(tables[",val,", 2]))"
)
if (val != length(rowCount))
htmlTbl <- paste(htmlTbl,",")
}
htmlTbl <- paste(htmlTbl,")")
return(htmlTbl)
}