Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 闪亮:通过批处理文件启动应用程序时存在编码/特殊字符问题_R_Batch File_Shiny_Shinydashboard - Fatal编程技术网

R 闪亮:通过批处理文件启动应用程序时存在编码/特殊字符问题

R 闪亮:通过批处理文件启动应用程序时存在编码/特殊字符问题,r,batch-file,shiny,shinydashboard,R,Batch File,Shiny,Shinydashboard,我正在编写一个小批量脚本来启动shinydashboard应用程序,这样不熟悉R的人就可以轻松访问该应用程序。到目前为止,一切都正常,除了通过批处理脚本启动应用程序时,特殊字符(即ä、ö和ü)没有正确显示。所有R文件均采用UTF-8编码保存。也许.bat文件中有一个选项我丢失了?我已经将Sys.setlocale()命令添加到R文件中,但这并没有解决问题。我构建了一个小示例来说明这个问题: apptest.R library(shiny) Sys.setlocale(category = "

我正在编写一个小批量脚本来启动shinydashboard应用程序,这样不熟悉R的人就可以轻松访问该应用程序。到目前为止,一切都正常,除了通过批处理脚本启动应用程序时,特殊字符(即ä、ö和ü)没有正确显示。所有R文件均采用UTF-8编码保存。也许.bat文件中有一个选项我丢失了?我已经将Sys.setlocale()命令添加到R文件中,但这并没有解决问题。我构建了一个小示例来说明这个问题:


apptest.R

library(shiny)

Sys.setlocale(category = "LC_ALL", locale = "German")

# Define UI ----
ui <- fluidPage(
  titlePanel("title panel with ä"),

  sidebarLayout(
    sidebarPanel("sidebar panel with ü"),
    mainPanel("main panel with ö")
  )
)

# Define server logic ----
server <- function(input, output) {

}

# Run the app ----
shinyApp(ui = ui, server = server, options = list(port = 7924))
source("<PATHTO>/app.R", encoding = "UTF-8", echo = TRUE)
library(shiny)

Sys.setlocale(category = "LC_ALL", locale = "German")

ui <- fluidPage(
  titlePanel("title panel with ä"),

  sidebarLayout(
    sidebarPanel("sidebar panel with ü"),
    mainPanel("main panel with ö")
  )
)

server <- function(input, output) {}

runApp(
  shinyApp(ui = ui, server = server, options = list(port = 7924))  
)

您可能需要为您的版本调整C:\Program Files\R\R-3.5.1\bin\Rscript.exe,或者如果已将“Rscript.exe”添加到路径中,则只需将其放在那里

如果您通过R-Studio启动应用程序,您将看到字母显示正确。如果通过.bat文件执行此操作,则如下所示:


在我看来,这似乎是一个编码问题,但我一直未能解决它。在这件事上有人能帮我吗?谢谢

当我遇到类似问题时,我可以建议一种解决方法

使用包装文件确保编码(此处:callAppEncoded.R)

脚本顺序为:

CMD/.bat--> callAppEncoded.R
源(“/app.R”,encoding=“UTF-8”)
--> 应用程序R

可复制示例(已测试):

CMD/.bat

start "" "C:\Program Files\R\R-3.5.1\bin\Rscript.exe" apptest.R
SLEEP 5
start "" http://127.0.0.1:7924
Rscript.exe  <PATHTO>/callAppEncoded.R

您是否尝试过在批处理文件中使用(使用cope页面
437
650
1252
65001
)?(虽然我对此没有太多希望,因为批处理脚本无法读取
.R
文件,所以我觉得这有点不合逻辑)此外,您应该将console字体更改为truetype字体。它对您有用吗?谢谢,它有用!我在源代码命令中添加了
echo=TRUE
,否则它将无法工作。