R绕过闪亮app的执行

时间:2018-06-09 14:05:56

标签: r function shiny

更新

使l l x x x x x x x x r r成为全局变量的解决方法,即

customcolors

必须处理R CMD注释,即

customcolors <<- NULL

我有R功能,它接收调色板并将其发送到打开闪亮的内部功能。此应用程序允许用户选择自定义颜色并将其保存到本地计算机上的文件(稍后我将添加删除此文件的功能,一旦值存储在变量中)。

我可以检索这些自定义颜色的唯一方法是在闪亮的应用程序运行后,在终端中输入

enter image description here

checking R code for possible problems ... NOTE
CustomPal : <anonymous> : <anonymous>: no visible binding for '<<-'
  assignment to 'customcolors'
CustomPal : <anonymous> : <anonymous>: no visible binding for global
  variable 'customcolors'
Undefined global functions or variables:
  customcolors

如果我在调用应用程序启动闪亮的函数中输入> CherryPickPalette("BiryaniRice","Kulfi","Haveli2") Listening on http://127.0.0.1:7420 Read 6 items > customcolors <- scan("colorfile.txt", character()) Read 6 items > customcolors [1] "#d94520" "#f0ecb0" "#4a121b" "#ecece9" "#5d5f64" "#5c4e48" > ,则R绕过执行闪亮

customcolors <- scan("colorfile.txt", character())

下面是函数(我正在修改),加上内部函数(整个R脚本在Github上),请指教

> CherryPickPalette("BiryaniRice","Kulfi","Haveli2")
Read 0 items
character(0)

这是内部功能:

CherryPickPalette <- function (name, name2=NULL, name3=NULL){

  new_pal <- NULL

  if ((nargs() < 2) || (nargs() > 3)){
    stop("Enter 2 or 3 valid palettes. Run ListPalette() for list of palettes.")
  }
  if (nargs() == 2){
    new_pal <- MergePalette(name,name2)
  }
  else if (nargs() == 3){
    new_pal <- MergePalette(name,name2,name3)
  }

  # calls the function that launches the app, no problem
  CustomPal(new_pal)

  # this is a problem that blocks CustomPal from being called
  colorfile <- paste(getwd(),"colorfile.txt",sep="/")
  if (file.exists(colorfile)){
    customcolors <- scan("colorfile.txt", character())
    customcolors
  }
  # this is a problem that blocks CustomPal from being called

}

0 个答案:

没有答案