简体   繁体   中英

how to change column names in rshiny using reactive function

I am uploading one csv file and to standardize the code I want to change the column names. so I am using following code:

Prv_mnth_so1 <- reactive({data.frame(lapply(data_uploaded1(),trimws))}) colnames(Prv_mnth_so1()) <- c("GST_ward","Category","order_and_section","combo") but this throws an error Warning: Error in <-: invalid (NULL) left side of assignment 52: server [#12] Error in colnames(Prv_mnth_so1()) <- c("GST_ward", "Category", "order_and_section", : invalid (NULL) left side of assignment

it means I can't assign () operator on right side but I am not able to fix this issue

You can only change the values of a reactive inside the reactive itself, because it is basically a function you evaluate (therefore you have to use the brackets).

You can either 1. try to change it directly when creating Prv_mnth_so1 or 2. later in another reactive context:

1.

Prv_mnth_so1 <- reactive({
  new_table <- data.frame(lapply(data_uploaded1(),trimws))
  colnames(new_table) <- c("GST_ward","Category","order_and_section","combo")
  new_table
  })
Prv_mnth_so1 <- reactive({data.frame(lapply(data_uploaded1(),trimws))})

output$table <- renderTable({
  table_data <- Prv_mnth_so1()
  colnames(table_data) <- c("GST_ward","Category","order_and_section","combo")
  table_data
})

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