简体   繁体   中英

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: 在此处输入图片说明

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]

Shiny is only recognizing one colname in your function colnames(table_1) <- c("","Value") and trying to assign it to two columns.

Try adding a name in your first column such as

colnames(table_1) <- c("Units","Value")

data.frame(Value=apply(...)) solved the problem!

output$table1 <- renderTable({
    data.frame(Value=apply(dataSource1(), 2, function(x) max(x, na.rm = TRUE)))

    })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM