You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shiny应用部署至shinyapps.io后,如何查找已发布文件路径?

Hey there! Let's work through your questions step by step to get those file path issues sorted out on shinyapps.io.

1. Finding the directory path of published files on shinyapps.io

Unlike your local machine, you can’t browse the server’s file system directly on shinyapps.io. But you can easily inspect the current working directory and file structure using code in your Shiny app.

The key tools here are getwd() (to fetch the current working directory) and list.files() (to list all files in the directory, including subfolders if you add recursive = TRUE). By adding a simple output component to your app, you can see exactly where your files live on the server.

2. Fixing broken resource paths after publishing

Your local code uses an absolute Windows path (E:/shiny/Correct) which shinyapps.io has no access to—this is why your MP4 and PDF files aren’t loading post-publish. Here’s how to fix it:

  • Move resources into your app project folder: Create a subfolder (e.g., pdf_folder) inside your Shiny app’s root directory, then copy all your media and PDF files into this folder.
  • Update addResourcePath to use a relative path: Instead of pointing to your local drive, use a path relative to your app’s root. For example:
    addResourcePath("pdf_folder", "./pdf_folder")
    
    If you want extra reliability, use the here package: addResourcePath("pdf_folder", here::here("pdf_folder")) (just make sure to install and load here first).
  • Include all files when publishing: When you publish from RStudio, check the box next to your pdf_folder (and all its contents) to ensure they get uploaded to shinyapps.io.
3. Checking the current file path in your published app

To confirm the server’s file structure and path, add this code to your app:

UI Component

verbatimTextOutput("server_path_details")

Server Logic

output$server_path_details <- renderPrint({
  cat("Current working directory on server:\n", getwd(), "\n\n")
  cat("All uploaded files and folders:\n")
  list.files(recursive = TRUE)
})

When you run the published app, this will display the exact working directory and a full list of uploaded files—you can use this to verify that your pdf_folder and its contents are present.

Once you’ve updated the path and confirmed the files are uploaded, your media and PDFs should work just like they did locally!

内容的提问来源于stack exchange,提问作者Ester Silva

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:19:34