Shiny应用googleVis图表下载服务器权限问题求助
Hey there, let’s get this download button working for your Shiny app! The core issue is that when deployed to the server, your app can’t create the temporary gg.html file or use webshot to capture it. Here’s a clear, non-R-focused checklist for your IT team to follow:
1. Fix Permissions for the Shiny App Directory
- Locate the folder where your Shiny app is deployed on the server (common default path:
/srv/shiny-server/[your-app-folder]) - Ensure the system user running the Shiny service (usually named
shiny) has read, write, and execute permissions for this folder - Run these commands (replace the path with your actual app folder):
sudo chown -R shiny:shiny /srv/shiny-server/[your-app-folder] sudo chmod -R 755 /srv/shiny-server/[your-app-folder]
2. Install PhantomJS (Required for webshot)
The webshot package needs PhantomJS to render HTML into images—this is often missing on servers:
- For Debian/Ubuntu systems:
sudo apt-get update && sudo apt-get install phantomjs - For RHEL/CentOS systems:
sudo yum install phantomjs - If the system package manager doesn’t have PhantomJS, they can run this in the Shiny user’s R environment:
webshot::install_phantomjs()
3. Use a Local Temp Folder (Avoid System Temp Restrictions)
Some servers lock down system temporary directories. To bypass this:
- Ask your IT team to add a small tweak to your app’s
server.R: create a local temp folder at the start of theshinyServerfunction:shinyServer(function(input, output) { # Add this line first dir.create("app_temp", showWarnings = FALSE) # Rest of your code... }) - Then update the file paths in the download handler to use this folder:
print(g, file = "app_temp/gg.html") webshot(url = "app_temp/gg.html", file = "app_temp/output.png") file.copy("app_temp/output.png", file) file.remove("app_temp/gg.html") file.remove("app_temp/output.png") - Make sure the
shinyuser has write access to this newapp_tempfolder (the permissions command from step 1 will cover this if it’s inside your app folder)
4. Check Security Policies Blocking Local File Access
The error "The requested URL was rejected" suggests a firewall or security tool (like ModSecurity) is blocking the app from accessing local files:
- Ask IT to check if there are rules preventing the Shiny service from accessing files via local paths or the
file://protocol - Add your app’s deployment folder to the security tool’s whitelist to allow local file access
After completing these steps, have your IT team restart the Shiny service:
sudo systemctl restart shiny-server
That should resolve the file creation and download issues!
内容的提问来源于stack exchange,提问作者guyabel

