R 错误:在应用程序中,只有字符串可以转换为符号

R 错误:在应用程序中,只有字符串可以转换为符号,r,shiny,R,Shiny,我试图在一个闪亮的应用程序中包含一个函数,当我运行它时,我遇到了以下错误: 警告:错误:只有字符串可以转换为符号 虽然可以改进和简化该功能,但它本身可以工作。我试着使用sym和ensym,但没有成功。我还试图了解是什么字符串和符号导致了这个问题 代码: 图书馆(闪亮) 图书馆(提问者) 图书馆(dplyr) 图书馆(GG2) 图书馆(tidyr) 图书馆(避风港) fre问题在于as_string。可以改成 fre <- function(var) { var_str1 <-

我试图在一个闪亮的应用程序中包含一个函数,当我运行它时,我遇到了以下错误:

警告:错误:只有字符串可以转换为符号

虽然可以改进和简化该功能,但它本身可以工作。我试着使用
sym
ensym
,但没有成功。我还试图了解是什么字符串和符号导致了这个问题

代码:


图书馆(闪亮)
图书馆(提问者)
图书馆(dplyr)
图书馆(GG2)
图书馆(tidyr)
图书馆(避风港)

fre问题在于
as_string
。可以改成

fre <- function(var) {
  var_str1 <- var
  var <- rlang::ensym(var)
  
  abc <- questionr::na.rm(dat[, var_str1])
  abc <- questionr::freq(abc, total = TRUE, na.last = TRUE, digits = 2)
  abc <- cbind(Label = rownames(abc), abc)
  abc <- questionr::rename.variable(abc, "n", "Frequency")
  abc <- questionr::rename.variable(abc, "%", "Percent")
  abc <- tidyr::separate(abc, Label, into = c("Value", "Label"),
        sep = "] ")
  row.names(abc) <- NULL
  abc <- abc %>% dplyr::mutate(Value = gsub("[[:punct:]]", '', Value)) %>% 
        dplyr::select(Label, Value, Frequency, Percent)
  abc
}

fre而不是
selected=NULL
你能传递
names(dat)[1]
我试着改变这个,但是变量“var1”不起作用对不起,这是一个输入错误,很好。但是它仍然不能工作。@TyperWriter
selectInput
s是字符向量,因此不需要所有函数参数作为符号而不是(字符)变量名传递的
tidyverse
“魔法”
fre <- function(var) {
  var_str1 <- var
  var <- rlang::ensym(var)
  
  abc <- questionr::na.rm(dat[, var_str1])
  abc <- questionr::freq(abc, total = TRUE, na.last = TRUE, digits = 2)
  abc <- cbind(Label = rownames(abc), abc)
  abc <- questionr::rename.variable(abc, "n", "Frequency")
  abc <- questionr::rename.variable(abc, "%", "Percent")
  abc <- tidyr::separate(abc, Label, into = c("Value", "Label"),
        sep = "] ")
  row.names(abc) <- NULL
  abc <- abc %>% dplyr::mutate(Value = gsub("[[:punct:]]", '', Value)) %>% 
        dplyr::select(Label, Value, Frequency, Percent)
  abc
}