I’m currently using a shiny server with Ubuntu as the operating system. I’m really new to shiny but attempted created my first survey with the hopes of collecting user inputs and writing them in a csv file.
Locally, it works (i.e. responses get saved in a local folder). However, when I developed a shiny app within my new R Studio server to test it, there is an error which reads:
"Error: cannot open the connection"
This occurs when I press the submit button. I think the error occurs because my shiny server doesn’t have rights to save files in my desired folder, i.e.
/home/my_user/test
The folder I’d save the responses would be located in that shiny folder in my new R Studio directory.
I’ve checked extensively on the website and I found:
Write permission from shiny app
Permission denied while using write.csv on ubuntu server
This is my saveData function:
saveData <- function(data) {
fileName <- sprintf("%s_%s.csv", humanTime(), digest::digest(data))
write.csv(x = data, file = file.path(responsesDir, fileName), row.names = FALSE, quote = TRUE)
}
The response directory (responsesDir) is
/home/my_user/test/csv_files
I’ve tried the following:
sudo chown shiny:shiny /var/shiny-server/test/
It says that there is no such file or directory.
Am I missing something very obvious? Thank you so much!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
Your diagnosis is likely correct, the error is most likely due to insufficient write permissions for the shiny user in the directory where you’re trying to save the csv file.
Your attempt to change the ownership of the directory to shiny with sudo chown shiny:shiny /var/shiny-server/test/ was a good start, but it seems like the folder /var/shiny-server/test/ does not exist which is why you got the “no such file or directory” error.
Since you are trying to write to /home/my_user/test/csv_files, you should try to change the ownership of this directory to the shiny user instead. You can do this by running the following command:
sudo chown -R shiny:shiny /home/my_user/test/
Here -R option is used to change the ownership recursively, meaning it will apply to all files and directories within /home/my_user/test/.
This command gives the shiny user permission to read, write, and execute in the directory /home/my_user/test/ and all its subdirectories, which includes /home/my_user/test/csv_files.
Also, do remember to restart the Shiny server after changing the ownership to make sure the changes take effect. You can do this by running sudo systemctl restart shiny-server.
Please note, it’s not generally considered best practice to have a system user like shiny writing to a personal user’s home directory. You might want to consider creating a directory in a neutral location for storing these files.
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.