[英]How do I change the column name in a reactive data frame?
I am calling the following function: 我正在调用以下函数:
output$table1 <- renderTable({
data.frame(apply(dataSource1(), 2, function(x) max(x, na.rm = TRUE)))
})
and it is producing a table with the column name: apply(dataSource1(), 2, function(x) max(x, na.rm = TRUE)
as shown in the photo below: 并产生一个表,其列名称为:
apply(dataSource1(), 2, function(x) max(x, na.rm = TRUE)
,如下图所示:
How do I rename the column to not show the function call as the column name? 如何重命名列以不将函数调用显示为列名? I want to rename it to "Value" or something along those lines.
我想将其重命名为“值”或类似的名称。
When I try: 当我尝试:
output$table1 <- renderTable({
table_1 <- data.frame(apply(dataSource1(), 2, function(x) max(x, na.rm = TRUE)))
colnames(table_1) <- c("", "Value")
})
I get the error: names' attribute [2] must be the same length as the vector [1]
我收到错误消息:
names' attribute [2] must be the same length as the vector [1]
Shiny is only recognizing one colname in your function colnames(table_1) <- c("","Value") and trying to assign it to two columns. Shiny仅识别函数colnames(table_1)<-c(“”,“ Value”)中的一个名称,并尝试将其分配给两列。
Try adding a name in your first column such as 尝试在第一列中添加名称,例如
colnames(table_1) <- c("Units","Value") colnames(table_1)<-c(“单位”,“值”)
data.frame(Value=apply(...))
solved the problem! data.frame(Value=apply(...))
解决了这个问题!
output$table1 <- renderTable({
data.frame(Value=apply(dataSource1(), 2, function(x) max(x, na.rm = TRUE)))
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.