[英]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.我正在上传一个 csv 文件并标准化我想要更改列名称的代码。 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 Prv_mnth_so1 <- reactive({data.frame(lapply(data_uploaded1(),trimws))})
colnames(Prv_mnth_so1()) <- c("GST_ward","Category","order_and_section","combo")
但这会抛出错误警告:<-:分配 52 左侧的无效(NULL)错误:服务器 [#12] 列名错误(Prv_mnth_so1())<- c(“GST_ward”,“Category”,“order_and_section”,:无效(NULL) 赋值的左侧
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).您只能在
reactive
本身内部更改reactive
的值,因为它基本上是您评估的函数(因此您必须使用括号)。
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
或 2. 稍后在另一个反应上下文中尝试直接更改它:
1. 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
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.