简体   繁体   English

从 Windows 命令行运行 R 代码的单行代码

[英]Single line code to run R code from Windows command line

I Want a single line code to run a shiny app from windows command line without opening the R application.我想要一个单行代码从 Windows 命令行运行一个闪亮的应用程序,而无需打开 R 应用程序。

If I open the R from cmd and run the code it works.如果我从 cmd 打开 R 并运行它的代码。 But it gives error for the following single line code.但是它为以下单行代码提供了错误。

R -e 'shiny::runApp(system.file("examples/01_hello", package="shiny"), launch.browser = T)'

............
............
> 'shiny::runApp(system.file(examples/01_hello,
+
+ Error: unexpected end of input
Execution halted

Please help.请帮忙。 Thanks..谢谢..

The following code is working:以下代码正在运行:

RScript -e "shiny::runApp(system.file('examples/01_hello', package='shiny'), launch.browser = T)"

I have made two changes:我做了两个改变:

  1. Replace R by RScript用 RScript 替换 R
  2. Interchange single and double quotes交换单引号和双引号

您可以尝试在 Windows 命令提示符下,单引号不适用于这种情况。

R -e "shiny::runApp(system.file("'examples/01_hello'", package="'shiny'"), launch.browser = T)"

You can try in cmd something like this (for example)您可以在 cmd 中尝试这样的操作(例如)

> "C:\Program Files\R\R-3.5.0\bin\i386\Rscript.exe" ".\app.R"

Inside app.R i have, so it is runs shiny app在 app.R 我有,所以它运行闪亮的应用程序

shinyApp(
  ui = ui,
  server = server,
  options = list(launch.browser = T))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM