目前,我的功能可以启动闪亮的应用程序,获取用户输入,一旦人关闭闪亮的窗口就保存到全局变量。
我想添加 ActionButton 来关闭闪亮而不是人不得不关闭窗口
ActionButton 关闭闪亮 --- 但它绕过了代码session$onSessionEnded
运行 Shiny 终端后显示它扫描了调色板的值,但cherrypickedpalette 的全局变量为 NULL
> CherryPickPalette("BiryaniRice","Kulfi","Haveli2")
Listening on http://127.0.0.1:5345
Read 8 items
> cherrypickedpalette
NULL
这是整个 R 脚本
调用函数
CherryPickPalette <- function (name, name2=NULL, name3=NULL){
#snipped code#
cherrypickedpalette <- CustomPal(new_pal)
#snipped code#
}
闪亮的功能
CustomPal <- function(new_pal){
if (interactive()){
#snipped code#
}
cherrypickedpalette <- runApp(list(
#snipped code#
mainPanel(
h5('Your Cherry-Picked Palette',style = "font-weight: bold;"),
fluidRow(column(12,verbatimTextOutput("col"))),
actionButton("action", label = "I'm Done")
)
),
server = function(input,output,session){
outputdata<- reactive({
input$col
})
output$col <- {
renderPrint(outputdata())
}
#Code to detect closing button
observe({
if (input$action > 0)
stopApp()
})
#Code to detect closing button
session$onSessionEnded(function(){
message <- paste(isolate(outputdata())," ")
cat(message,file=colorfile, append=TRUE)
cherrypickedpalette <<- scan(file=colorfile," ")
stopApp(cherrypickedpalette)
file.remove(colorfile)
})
}
)
)
}
}