问题
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
回答1:
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
})
来源:https://stackoverflow.com/questions/64349166/how-to-change-column-names-in-rshiny-using-reactive-function