R Shiny:table 中的 dnn 未出现在 renderTable() 中
R Shiny: dnn in table not appearing in renderTable()
我有一个用 renderTable()
制作的 table,我想标记行和列(不是每个,只是整体)。当我 运行 控制台中的代码时,标签出现了。但是当我 运行 在活动的闪亮环境中使用 renderTable()
的代码时, table 出现时没有标签。这是我的(总结的)代码:
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
})
})
当我在控制台中 运行 output$pairs 中的代码时,它会生成带有标签的 table(这是我想要的):
age
hiv 40 45 50 55 60
0 1 0 2 1 1
1 1 1 1 1 1
当我 运行 通过 Shiny 时,它绘制相同的 table,只是没有任何标签。知道为什么吗?
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)
})
我有一个用 renderTable()
制作的 table,我想标记行和列(不是每个,只是整体)。当我 运行 控制台中的代码时,标签出现了。但是当我 运行 在活动的闪亮环境中使用 renderTable()
的代码时, table 出现时没有标签。这是我的(总结的)代码:
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
})
})
当我在控制台中 运行 output$pairs 中的代码时,它会生成带有标签的 table(这是我想要的):
age
hiv 40 45 50 55 60
0 1 0 2 1 1
1 1 1 1 1 1
当我 运行 通过 Shiny 时,它绘制相同的 table,只是没有任何标签。知道为什么吗?
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)
})