Currently, I have function that launches shiny app, gets user inputs, saves to global variable once person close shiny window.
I'd like to add ActionButton to close shiny instead of person having to close window
The ActionButton closes shiny --- but it bypasses the code in session$onSessionEnded
After running Shiny terminal shows it scanned in values of color palette, but global variable of cherrypickedpalette is NULL
> CherryPickPalette("BiryaniRice","Kulfi","Haveli2")
Listening on http://127.0.0.1:5345
Read 8 items
> cherrypickedpalette
NULL
Here is the entire R script
Calling function
CherryPickPalette <- function (name, name2=NULL, name3=NULL){
#snipped code#
cherrypickedpalette <- CustomPal(new_pal)
#snipped code#
}
Function with Shiny
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)
})
}
)
)
}
}