所以我的闪亮应用程序上有下一段代码:
observeEvent(input$change_type_btn,{
req(input$var_cambio)
selected_column <- input$var_cambio
data(data() %>% mutate(Age = as.numeric(Age)))
})
如您所见,y 有一个名为 data() 的数据框,我想将列的类型更改为数字。 作为示例,我使用存储为 char 类型的 Age 列。这非常有效。
但是当我有一个 SelectInput 时,我想选择要交换的列,如下所示:
selectInput(
"var_cambio",
label = "Selecciona la variable a cambiar de tipo:",
choices = c(names(data())),
multiple = FALSE,
selected = NULL
),
并将 Age 与 input$var_cambio 交换,应用程序在执行后立即关闭,返回“SourceUTF8(serverR, envir = new.env(parent = shareEnv)) 中的错误:错误采购 C:/....... /服务器.R
已经几个小时了,尝试了很多不同的事情,我已经达到了极限,我 99% 确定这是因为输入应该以其他方式使用,或者我错过了一些关于我还没有学过的主题的关键内容
我尝试了多种方法来使用输入,将其存储为辅助变量,但它不起作用
这有帮助吗?这可能与“mutate”没有从您的输入中接收到正确的列名称有关。
observeEvent(input$change_type_btn, {
# Ensure that a column has been selected
req(input$var_cambio)
# Convert the selected column name from string to a symbol
selected_column <- rlang::sym(input$var_cambio)
# Mutate the selected column to numeric, using non-standard evaluation
data <- data() %> %> mutate(!!selected_column := as.numeric(.[[selected_column]]))
})