running shiny from terminal

4,542 views
Skip to first unread message

Adrian Duşa

unread,
Jan 26, 2015, 4:27:09 PM1/26/15
to shiny-...@googlegroups.com
Hi,

I would like to still be able to use R while running a shiny app.
I thought about running this shiny app from the terminal, using a command like this:

$ Rscript -e 'library(shiny); runApp("shinyapp/")'

Error in AppWrapper$new : could not find function "loadMethod"
Calls: runApp -> startApp -> startServer -> $
Execution halted

Does anyone knows what this is?
Can I do something to overcome this?

Thanks,
Adrian

Joe Cheng

unread,
Jan 26, 2015, 6:29:18 PM1/26/15
to Adrian Duşa, shiny-...@googlegroups.com
One of these two will work:

Rscript -e 'library(methods); shiny::runApp("shinyapp/", launch.browser=TRUE)'

or

R --slave --no-restore -e 'shiny::runApp("shinyapp/", launch.browser=TRUE)'



--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/ec9c4189-998b-4fcb-a362-bf611384f315%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adrian Duşa

unread,
Jan 27, 2015, 5:38:59 AM1/27/15
to Joe Cheng, shiny-...@googlegroups.com
Sweet!
Thanks very much,
Adrian
--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

David Chudzicki

unread,
May 20, 2015, 7:55:51 AM5/20/15
to shiny-...@googlegroups.com, j...@rstudio.com
I just ran into this. Thanks for the answer -- very helpful.

Does the necessity for the user to explicitly load `methods` indicate that there's a dependency on methods which isn't correctly expressed in the `shiny` package?

Joe Cheng

unread,
May 20, 2015, 10:40:03 AM5/20/15
to David Chudzicki, shiny-...@googlegroups.com
No, it's just what Rscript requires you to do. It's a well documented quirk of Rscript, it omits methods from the default package list for performance reasons. 

Sent from Outlook

David

unread,
May 21, 2015, 11:44:05 AM5/21/15
to Joe Cheng, shiny-...@googlegroups.com
Having to explicit load `methods` is a hassle for users (and confusing
to people who haven't encountered this before). I realize it's a quirk
of RScript, but I think it's a quirk that means package authors should
make the dependence on `methods` explicit.

Seems like it would be better to add `methods` to the "Depends: ..."
(e.g. like Hadley did for testthat in response to this issue:
https://github.com/hadley/testthat/issues/122).

According to this (http://r-pkgs.had.co.nz/description.html), adding
it to "Imports: ..." instead of "Depends: ..." should work for users
of R 3.2.0+.
--
David J. Chudzicki
http://davidchudzicki.com
dch...@gmail.com
(518) 366-7303

Joe Cheng

unread,
May 21, 2015, 12:45:13 PM5/21/15
to David, shiny-...@googlegroups.com

David

unread,
May 21, 2015, 1:03:36 PM5/21/15
to Joe Cheng, shiny-...@googlegroups.com
Awesome, thanks!

Yihui Xie

unread,
May 21, 2015, 1:04:40 PM5/21/15
to David, Joe Cheng, shiny-discuss
The motivation of not loading the methods package was to save some
time when starting up R. Turns out the time saved is about 0.05
seconds, and this 0.05 seconds have wasted so many people countless
hours. Yeah, this thing has been confusing for several years. Depends
won't work for R CMD check because when you load a package (e.g.
shiny::column), the Depends packages will not be attached. It can also
be problematic when another package imports a function from shiny, and
methods in Depends will also be ignored.

According to your reference to Hadley's book, it seems the problem has
been fixed, but I do not see a NEWS item in R 3.2.0. If it has really
been fixed, they should have been shouting from the rooftops in the
NEWS!

Regards,
Yihui

Ashutosh Singh

unread,
Apr 24, 2017, 3:54:33 PM4/24/17
to Shiny - Web Framework for R, dch...@gmail.com
Hey Joe,

I used the latest release of Shiny and created a server and UI in one file (test.R).  This works file in RStudio but I am not able to run this from the command line.

Would you have any thoughts on how to do this?

thanks
Ashu

Adrian Dușa

unread,
Apr 24, 2017, 4:03:18 PM4/24/17
to Ashutosh Singh, Shiny - Web Framework for R, dch...@gmail.com
On Mon, Apr 24, 2017 at 10:54 PM, Ashutosh Singh <singh...@gmail.com> wrote:
Hey Joe,

I used the latest release of Shiny and created a server and UI in one file (test.R).  This works file in RStudio but I am not able to run this from the command line.

Hi,
But what exactly did you try and didn't work?
Did you use Rscript or R --slave ?

Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92

Ashutosh Singh

unread,
Apr 24, 2017, 6:48:08 PM4/24/17
to Adrian Dușa, Shiny - Web Framework for R, dch...@gmail.com
Both 

Best
Ashu

Ashutosh Singh

unread,
Apr 24, 2017, 8:33:55 PM4/24/17
to Adrian Dușa, Shiny - Web Framework for R, David Chudzicki
I created a directory "D:\Documents\WQU\Courses\2 - Statistics\Assignments\Unit 1 CS" and in there, I have a file called app.R (attached).

Further, 'created a batch file called test.bat that had the following lines:

Rscript "D:/Documents/WQU/Courses/2 - Statistics/Assignments/run.R"

Would appreciate any help!

Thank you
-A



Ashutosh Singh, CFA
(917) 952 3388
app.R
run.R

Adrian Dușa

unread,
Apr 24, 2017, 8:47:11 PM4/24/17
to Ashutosh Singh, Shiny - Web Framework for R, David Chudzicki
There are already two solutions given by Joe Cheng in this thread, if your didn't read it:

Rscript -e 'library(methods); shiny::runApp("shinyapp/", launch.browser=TRUE)'

or

R --slave --no-restore -e 'shiny::runApp("shinyapp/", launch.browser=TRUE)'

Please pay attention to the library(methods) required by Rscript, which you seem to prefer. I went for the second approach, and even got to create executable icons:

I hope this helps,
Adrian

Ashutosh Singh

unread,
Apr 24, 2017, 9:37:24 PM4/24/17
to Adrian Dușa, Shiny - Web Framework for R, David Chudzicki

On Mon, Apr 24, 2017 at 8:46 PM, Adrian Dușa <dusa....@unibuc.ro> wrote:
R --slave --no-restore -e 'shiny::runApp("shinyapp/", launch.browser=TRUE)'

Those are the two methods I tried from a DOS command prompt. The app.R file that contains the server and ui code is a sub-directory called "Unit 1 CS". 

Both commands give me an error:
Error: unexpected end of input
Execution halted

The two commands I tried were:
Rscript -e 'library(methods); shiny::runApp("Unit 1 CS/", launch.browser=TRUE)'

Or

R --slave --no-restore -e 'shiny::runApp("Unit 1 CS/", launch.browser=TRUE)'

Joe Cheng

unread,
Apr 26, 2017, 5:44:39 PM4/26/17
to Ashutosh Singh, Adrian Dușa, Shiny - Web Framework for R, David Chudzicki
I'd expect that to work (I do something like this every day on my Mac). Can you try it with a trivial app in app.R?

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

Otmane Jai

unread,
Aug 29, 2017, 11:30:52 AM8/29/17
to Shiny - Web Framework for R
Hi ,

I just ran into this. Thanks for the answer -- very helpful.

can we do the same thing but this time for stopping the App (assume we know which server and which port the app is running in) ?

I am using shiny on windows and run my app on my local computer.
My objective is to stop the App to update some data and then re-launch it. and Ia m looking for a way to do this automatically (thought about scheduling a script with rstudio)

thks vm

Kyle Bachmayer

unread,
Jan 8, 2018, 4:47:32 PM1/8/18
to Shiny - Web Framework for R
I rearranged the syntax and was able to get it to run. Too bad about these small syntax things. Should be better standardized so that people don't get tripped up on things like this.

Rscript -e "library('methods');shiny::runApp('app_folder/', launch.browser=TRUE)"
Reply all
Reply to author
Forward
0 new messages