Writing to file, works fine when executed on the host server on client side fails with "cannot open file, no such file or directory"

...Hi,
I recently built an app using shiny, which reads some data and generates a bunch of plots that are written to a user selected location. The code just runs fine when run in R studio. I deployed the app to a local shiny server, it works fine when executed from the browser on the server itself. But when the same app when run from a different desktop fails with the error message "cannot open file "c:/users/.../xyz.png" no such file or directory. Error in file: cannot open the connection.
what might be wrong here?
The code inserver.R is as follows:
#This is executed when an action button is pressed.
data1 <- eventReactive(input$action2,{
#Reading files and some processing later...
p=ggplot(tt,aes(as.factor(variable),value,col=as.factor(variable),label=geneMod))+geom_jitter()+theme(axis.text.x = element_text(angle = 90, hjust = 1),legend.position = "none")+labs(x="Readouts",y="Cells Divided >2")+geom_boxplot()+geom_violin()+geom_text(data = subset(tt, (tolower(gene)%in%tolower(protein.interest))),col="black",cex=3,fontface=2)+ylim(-6, 6)

      suppressGraphics(ggsave("PerCD4Gt2.png", plot = p, device = "png", path = op(),
                              width = 9, height = 6, units = c("in")))

})
Thanks for reading,
Best,
Jahangheer

The code running on shinyapp.io doesn't have access to your local filespace.

My first suggestion is to write the file to a temporary file (use tempdir() etc)
You can provide client side access to this by having a shiny downloadButton. The downloadhandler can get its content from the temporary file and pass it to wherever the user chooses (via the browser) to save it to

Great! Just what I wanted. Made changes as per your suggestion and after taking care of some nagging issues, it worked finally. Thanks!

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.