将Rmarkdown发布到Shiny Server上的Blogdown后图表不显示
Hey there! Let's figure out why your Rmarkdown charts aren't showing up after deploying your Blogdown site to Shiny Server. Based on the details you shared, here are the most practical fixes to try:
1. 排查文件权限问题
Shiny Server runs under the shiny user by default, but your public folder lives in /home/runrunwei/GitRepo/MySite/—it’s super likely the shiny user doesn’t have read access to this directory chain.
- First, set the correct permissions to let the
shinyuser traverse and read your files:sudo chmod -R o+r /home/runrunwei/GitRepo/MySite/ sudo chmod o+x /home/runrunwei/ sudo chmod o+x /home/runrunwei/GitRepo/ sudo chmod o+x /home/runrunwei/GitRepo/MySite/ - Test if the
shinyuser can access your post files directly:
If this throws an error, the permission fix above should resolve it.sudo -u shiny ls /home/runrunwei/GitRepo/MySite/public/post/
2. Verify chart file paths are correct
Blogdown stores Rmarkdown charts in paths like public/post/[your-post-name]/index_files/figure-html/. When using a symlink with Shiny Server, relative paths might break.
- Open your browser’s developer tools (F12), go to the Network tab, then refresh your site:
- If chart requests show a 404 error, the path mapping is off. Try setting
baseurl = "/bi/"in your Blogdownconfig.toml(orconfig.yaml), rebuild the site withblogdown::build_site(), then update yourpublicfolder.
- If chart requests show a 404 error, the path mapping is off. Try setting
3. Check Shiny Server logs for specific errors
Logs will tell you exactly what’s going wrong—like permission denials or missing files.
- View the latest log entries for your site:
(Ifsudo tail -n 20 /var/log/shiny-server/bi.logbi.logdoesn’t exist, check other files in/var/log/shiny-server/.) Look for keywords likePermission deniedorFile not foundto pinpoint the issue.
4. Try copying the public folder instead of using a symlink (backup plan)
Symlinks can sometimes cause permission or mapping headaches. If the above steps don’t work, copy the folder directly:
sudo cp -r /home/runrunwei/GitRepo/MySite/public/ /srv/shiny-server/bi/
Just re-copy the folder whenever you update your site—this avoids symlink-related issues entirely.
Give these steps a shot, and your charts should start showing up in no time!
内容的提问来源于stack exchange,提问作者Rain.Wei

