【发布时间】:2018-10-19 16:54:40
【问题描述】:
我正在制作我的第一个 Shiny 应用程序,但找不到任何关于如何显示使用 htmlTable 包创建的表格的示例。我基本上想在按下按钮时创建一个表格并显示它。
Shiny 显示 html 代码而不是表格。我不知道用什么替换 server-part 中的“renderTable”和 ui-part 中的 tableOutput。
我没有使用普通表格,因为我需要 htmlTable 包中提供的跨列功能。
library(shiny)
library(htmlTable)
#################### ui part ##############################################
ui <- pageWithSidebar(
headerPanel("Tables"),
sidebarPanel(
actionButton("goButton", "Run Table")
),
mainPanel(
tableOutput("filetable")
)
)
#################### server part #######################################
server <- function(input,output)
{
selectedData <- eventReactive(input$goButton, {
# Create the table (using table from htmlTables doc as example)
htmlTable(matrix(paste("Content", LETTERS[1:16]),
ncol=4, byrow = TRUE),
header = paste(c("1st", "2nd",
"3rd", "4th"), "header"),
rnames = paste(c("1st", "2nd",
"3rd", "4th"), "row"),
rgroup = c("Group A",
"Group B"),
n.rgroup = c(2,2),
cgroup = c("Cgroup 1", "Cgroup 2†"),
n.cgroup = c(2,2),
caption="Basic table with both column spanners (groups) and row
groups",
tfoot="† A table footer commment")
})
output$filetable <- renderTable({selectedData()})
}
shinyApp(ui,server)
【问题讨论】: