I have a function that (among other things) pastes together the elements of an array, something like this:
f <- function(){
xy <- c("x", "y")
pxy <- paste(xy, collapse = " and ")
ans <- paste(pxy, "exist")
answer <<- ans
return(ans)
}
When I run it directly in R, answer looks just like you'd expect it too: x and y exist
When I run it via a shiny button, answer looks like: c("x", "y") and y exist
Any ideas what could be going on here?
[NB: Sorry for not including code that can reproduce the error. My app is many thousand lines long, and I cannot reproduce the pattern in a simple example.]
here is a working reprex in a shiny context.
I wonder if you might have oversimplied your f(), I would have expected you to be passing parameters, to get different effects ? The issue might be what you are trying to pass...
library(shiny)
f <- function(){
xy <- c("x", "y")
pxy <- paste(xy, collapse = " and ")
ans <- paste(pxy, "exist")
return(ans)
}
ui <- fluidPage(
actionButton("runme","run"),
textOutput("txtout")
)
server <- function(input, output) {
output$txtout<-renderText({
req(input$runme)
f()
})
}
# Run the application
shinyApp(ui = ui, server = server)
The arg list contains several very complicated objects, and there was a subtle difference in the way I was constructing them from the command line compared to the way the app was constructing them.
If I do pxy <- paste(unlist(xy)) in the real code, it works.