【发布时间】:2020-11-24 12:25:37
【问题描述】:
我正在编写一个闪亮的应用程序,它获取用户上传的数据并根据他们数据中的任何变量计算汇总统计数据。如果您使用 iris 数据集作为示例,用户可以上传该数据集并按物种计算步长的汇总统计。我有代码可以为每个统计数据创建一个汇总表,但我希望能够创建一个表格,其中包含一个空间中的所有汇总统计数据。我正在使用的一段代码如下。您将看到用于计算平均值和中位数的代码,但它显示为两个表格。有没有办法对此进行调整,以便我可以在一个表中包含多个表达式?
server <- function(input, output, session) {
data <- reactive({
file1 <- input$csvFile
if (is.null(file1)) {
return()
}
data = read.csv(file=file1$datapath)
data
})
output$var_dem <- renderUI({
selectInput("dem", "Select a demographic variable.", choices= names(data()))
})
output$var_ui <- renderUI({
selectInput("var", "Select an outcome variable.", choices= names(data()))
})
output$mean <- renderTable(
tapply(data()[,input$var], data()[,input$dem], mean),
rownames = TRUE,
colnames = FALSE
)
output$median <- renderTable(
tapply(data()[,input$var], data()[,input$dem], median),
rownames = TRUE,
colnames = FALSE
)
【问题讨论】:
-
为了其他人可以帮助您,请发布一个可复制的示例:stackoverflow.com/questions/5963269/…