部署Shiny应用至shinyapps.io时出现区域设置检测错误
First, let's recap your issue clearly:
Error detecting locale: Error in read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'raw' (Using default: en_US)
Your local sessionInfo() output:
R version 3.4.0 (2017-04-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252
You suspect this is an encoding conflict since your RStudio uses English settings but runs on a French Windows system — that's a solid hunch! Here are actionable fixes to try:
1. Force Locale Settings Directly in Your App
Add this code at the very top of your app.R (or in global.R if you split your app into multiple files) to explicitly set the locale that matches your local setup:
# Explicitly set locale to match your local configuration Sys.setlocale(category = "LC_ALL", locale = "English_United States.1252")
This tells shinyapps.io to use the exact locale you're working with locally, bypassing the problematic automatic detection step that's throwing the error.
2. Disable Automatic Locale Detection
Sometimes the auto-detection process is the root issue. You can skip it entirely using these methods:
- RStudio Deploy Button: Before deploying, go to Tools > Global Options > Publishing > shinyapps.io and look for an option to disable locale detection (it might be labeled "Skip locale check" or similar).
- rsconnect Package: If you deploy via code, add the
localeparameter to yourdeployApp()call to explicitly set it:
library(rsconnect) deployApp(appDir = "./your-app-directory", locale = "en_US")
3. Fix Hidden Encoding Issues in App Files
Even with correct locale settings, hidden encoding mismatches in your app's files can trigger this error. Try these checks:
- Open all your R scripts in RStudio, go to File > Reopen with Encoding and select
Windows-1252(matching your system's locale encoding), then re-save them. - For data files (like CSVs), ensure you save them with explicit encoding. When using
write.csv(), add thefileEncodingparameter:
write.csv(your_data, "data.csv", fileEncoding = "Windows-1252")
4. Upgrade Your R Version (Optional but Highly Recommended)
Your current R version (3.4.0) is quite outdated (released in 2017). Newer R versions (4.x and above) have significantly improved handling of locale detection and cross-platform encoding inconsistencies. Upgrading might resolve this issue entirely, along with other potential bugs you might encounter.
Start with step 1 first — it's the quickest fix tailored to your specific setup. If that doesn't work, move through the other steps one by one.
内容的提问来源于stack exchange,提问作者Tochoka

