我有一张用renderTable()
制作的表格,我想标记行和列(不是每一行,只是整体)。当我在控制台中运行代码时,会出现标签。但是当我在renderTable()
的活动Shiny环境中运行代码时,表格中没有标签。这是我的(汇总)代码:
shinyUI(pageWithSidebar(
headerPanel("Hello Shiny!"),
sidebarPanel(),
mainPanel(
tabPanel("Pairwise Table", tableOutput("pairs") )
))
shinyServer(function(input, output, session) {
output$pairs <- renderTable({
dat <- data.frame(hiv=c(0,1,0,0,0,1,1,0,1,1),
age=c(50,55,50,60,40,45,40,55,50,60))
tab <- table(dat$hiv, dat$age, dnn=c("hiv","age"))
tab
})
})
当我在控制台的输出$ pairs中运行代码时,它会生成带有标签的表(这就是我想要的):
age
hiv 40 45 50 55 60
0 1 0 2 1 1
1 1 1 1 1 1
当我通过Shiny奔跑时,它会绘制同一张桌子,没有任何标签。知道为什么?
答案 0 :(得分:1)
似乎Shiny不支持这种表格显示。我开发了一个工作,希望它有用。
不使用table
,而是使用ftable
,并将其包装在data.frame
中。以下是shinyServer
应该如何:
shinyServer(function(input, output, session) {
output$pairs <- renderTable({
dat <- data.frame(hiv=c(0,1,0,0,0,1,1,0,1,1),
age=c(50,55,50,60,40,45,40,55,50,60))
tab <- data.frame(format(ftable(dat),
method = "compact", quote = F))
tab
}, include.rownames=FALSE, include.colnames = FALSE)
})