1

All, I am trying to write a data frame into RDS file in Shiny app. I am using below code.

AgName <- gsub("\\s","",paste(mtrl1,'_',stage1,'_',sample1,'.RDS', collapse = ' '))
saveRDS(Input_Data2, AgName )

But it is throwing following error message:

Error: cannot open the connection

Same code is running fine on R command line but not in Shiny app. Any help will be highly appreciated. Thanks!


Thanks Flick!

I used below code as well, but no luck.

setwd("/opt/shiny-server/samples/sample-apps/P-AG-Disc4/")
AgName <- gsub("\\s","",paste(mtrl1,'_',stage1,'_',sample1,'.csv', collapse = ' '))
saveRDS(Input_Data2, file=AgName )

Thanks Flick!

You were right. Directory was not having write permission on the directy, where I was trying to write. Thanks again soo much!

A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76
Piyush
  • 1,571
  • 4
  • 14
  • 21
  • It's likely R and Shiny might have different working directories when they run by default. Try looking at the results from `getwd()` from each and make sure Shiny is writing to the place you think it is and has permissions to do so. Or at least show us the value of `AgName` – MrFlick Jun 04 '14 at 15:26
  • Can you verify the value of `AgName` is correct? – MrFlick Jun 04 '14 at 15:32

1 Answers1

4

I was getting the same issue. I referred to this question and used the below given code to resolve this. I used this code, and it ran fine:

  wrtfun2<-reactive({
  if (!is.null(input$var1))
  setwd("/opt/shiny-server/samples/sample-apps/test")
  sink("outfile.txt")
  cat(input$var1)
  sink()
  }
)

I also changed the permission on the directory where I was trying to write and It worked finally.

Community
  • 1
  • 1
Piyush
  • 1,571
  • 4
  • 14
  • 21