更新,我尝试使用对象编写应用程序(解释here),但我得到相同的错误
更新了内部应用功能
CustomPalette <- function(new_pal=NULL){
if (interactive()){
colorfile <- paste(getwd(),"colorfile.txt",sep="/")
if (!file.exists(colorfile)){
file.create(colorfile)
}
app <- list(
ui = fluidPage(
titlePanel("Cherry Pick Your Own Palette!"),
sidebarPanel (hr(),
selectInput('col', 'Options', new_pal, multiple=TRUE, selectize=FALSE, size = 15)
),
mainPanel(
h5('Your custom colors',style = "font-weight: bold;"),
fluidRow(column(12,verbatimTextOutput("col"))))
),
server = function(input,output,session){
outputdata<- reactive({
input$col
})
output$col <- {
renderPrint(outputdata())
}
session$onSessionEnded(function(){
message <- paste(isolate(outputdata())," ")
cat(message,file=colorfile, append=TRUE)
customcolors <- scan(file=colorfile," ")
stopApp(customcolors)
customcolors
})
}
)
}
}
我试图用一个参数调用R Shiny App,即customcolors <- runApp(CustomPalette(new_pal = NULL))
这将启动闪亮的应用程序,允许用户选择应用程序作为向量返回的各种颜色
不幸的是,devtools::check()
给出了entire R script
> CherryPickPalette("GoldenTemple","AmritsariPedeWaliLassi")
Error in UseMethod("as.shiny.appobj", x) :
no applicable method for 'as.shiny.appobj' applied to an object of class "NULL"
Calls: CherryPickPalette -> runApp -> as.shiny.appobj
Execution halted
下面是CherryPickPalette
函数,它调用包含闪亮应用程序(也包括在内)的CustomPalette
函数。
最终,用户应该能够执行CherryPickPalette(name, name2, name3)
,应该出现闪亮的应用,用户应该选择他们想要的任何颜色,并且应该保存变量并在整个脚本中使用。
# visible to user
CherryPickPalette <- function (name, name2=NULL, name3=NULL){
### snipped code
customcolors <- runApp(CustomPalette(new_pal = NULL))
customcolors
}
# hidden from user
CustomPalette <- function(new_pal){
if (interactive()){
colorfile <- paste(getwd(),"colorfile.txt",sep="/")
if (!file.exists(colorfile)){
file.create(colorfile)
}
shinyApp(
ui = fluidPage(
titlePanel("Cherry Pick Your Own Palette!"),
sidebarPanel (hr(),
selectInput('col', 'Options', new_pal, multiple=TRUE, selectize=FALSE, size = 15)
),
mainPanel(
h5('Your custom colors',style = "font-weight: bold;"),
fluidRow(column(12,verbatimTextOutput("col"))))
),
server = function(input,output,session){
outputdata<- reactive({
input$col
})
output$col <- {
renderPrint(outputdata())
}
session$onSessionEnded(function(){
message <- paste(isolate(outputdata())," ")
cat(message,file=colorfile, append=TRUE)
customcolors <- scan(file=colorfile," ")
stopApp(customcolors)
customcolors
})
}
)
}
}