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

部署Shiny应用至shinyapps.io时出现区域设置检测错误

Fixing "Error detecting locale" When Deploying Shiny App to 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 locale parameter to your deployApp() 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 the fileEncoding parameter:
write.csv(your_data, "data.csv", fileEncoding = "Windows-1252")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:03:29