1

I Want a single line code to run a shiny app from windows command line without opening the R application.

If I open the R from cmd and run the code it works. 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..

Raja Saha
  • 399
  • 1
  • 11
  • https://stackoverflow.com/questions/18306362/run-r-script-from-command-line – Jonny Phelps Jan 11 '19 at 11:12
  • It looks as though you need to escape the quotes in your command string. The `shQuote()` function in R includes several ways to do that. Read the help page carefully to choose which type of escaping to do. – user2554330 Jan 11 '19 at 11:16
  • @JonnyPhelps I have already gone through the link.. Other simple code like r -e "cat(getwd(),'\n')" works.. but the code I am using gives error..... – Raja Saha Jan 11 '19 at 11:16
  • 1
    It doesn't work if you put your code in a .r file and use the Rscript command? Have you set up the environment variables for R? – Jonny Phelps Jan 11 '19 at 11:18
  • @user2554330 .. Copy Paste the code... Does not worked – Raja Saha Jan 11 '19 at 11:26
  • @JonnyPhelps RScript TestRScript.R also works.. It's mean environment variables for R is Ok ....??? – Raja Saha Jan 11 '19 at 11:27
  • Yeah should be, you can check by following these instructions, but adapt path to where your version of R is installed. http://yizhexu.com/2017/02/r-path/ – Jonny Phelps Jan 11 '19 at 11:50
  • @RajaSaha: yes, escaping for the cmd shell is hard. I'd use Jonny's suggestion: put your code in a file and run that. – user2554330 Jan 11 '19 at 11:54
  • @JonnyPhelps I don't have admin access to change the env path.. I think if there was a path setup problem then R -e "cat(getwd(),'\n')" also would not worked.. – Raja Saha Jan 11 '19 at 12:11

3 Answers3

1

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
  2. Interchange single and double quotes
Raja Saha
  • 399
  • 1
  • 11
0

You can try, in Windows command prompt, single quote doesn't work for this case.

R -e "shiny::runApp(system.file("'examples/01_hello'", package="'shiny'"), launch.browser = T)"
Qianbo Wang
  • 566
  • 4
  • 10
  • Not working.. Output: 'The filename, directory name, or volume label syntax is incorrect.' – Raja Saha Jan 14 '19 at 06:44
  • @RajaSaha Updated my original answer, seems like in windows command prompt, the quotes are nightmares. I tried R -e "cat(getwd(), "'\n'")" and it works on my windiws – Qianbo Wang Jan 14 '19 at 14:35
0

You can try in cmd something like this (for example)

> "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

shinyApp(
  ui = ui,
  server = server,
  options = list(launch.browser = T))
fenix_fx
  • 384
  • 2
  • 10