部署含fileInput的Shiny应用遇上传失败问题求助
Let’s walk through the most likely fixes for your LinkedIn-focused HTML parser app—since it works locally but fails silently on shinyapps.io, the issue is almost always tied to environment differences or overlooked deployment details:
1. Fix Path & File Handling
Local machines let you read/write files freely, but shinyapps.io runs in a restricted container. Make sure you’re using Shiny’s built-in temporary file paths instead of hardcoded local paths. For example:
output$parsed_data <- renderTable({ uploaded_file <- input$html_upload if (is.null(uploaded_file)) return(NULL) # Use the temp path Shiny provides, not a local folder raw_html <- readLines(uploaded_file$datapath) # Your LinkedIn parsing logic here (rvest/xml2 calls) })
Avoid writing files to arbitrary directories—shinyapps.io only allows writes to the app’s temp directory or the www folder (with strict limits).
2. Validate Dependencies Are Fully Declared
Even if your app runs locally, shinyapps.io might be missing packages or using incompatible versions. Double-check:
- All required libraries (like
rvest,xml2,dplyr) are loaded with explicitlibrary()calls in yourapp.R/server.Rfiles. - Use
renvto lock in exact package versions:- Run
renv::init()locally to generate a lockfile - Include the
renvfolder andrenv.lockwhen deploying to shinyapps.io
- Run
This ensures the server uses the same package versions that worked for your local tests.
3. Dig Into Server Logs for Hidden Errors
Since you don’t get browser feedback, check the shinyapps.io logs for clues:
- Go to your app’s dashboard on shinyapps.io
- Click "Logs" in the sidebar
- Look for errors like:
- Failed package loading
- Encoding issues when reading HTML files
- Missing system libraries (e.g., libxml2 for HTML parsing)
If encoding is the problem, explicitly set it in readLines():
raw_html <- readLines(uploaded_file$datapath, encoding = "UTF-8")
4. Adjust File Upload Limits & Filters
shinyapps.io has a default 10MB upload limit—if your HTML files are larger, the upload will fail silently. Bump this limit by adding to the top of app.R:
options(shiny.maxRequestSize = 30*1024^2) # Sets limit to 30MB
Also, restrict your file input to only accept HTML files to avoid invalid uploads breaking parsing:
fileInput("html_upload", "Upload LinkedIn HTML File", accept = ".html")
5. Test for Local Environment Quirks
Sometimes local configurations (like custom .Rprofile settings, proxy rules, or system-level libraries) make the app work locally but fail on the server. Test your app in a clean R session (no custom profiles) to rule out these edge cases.
内容的提问来源于stack exchange,提问作者Gautam

