Any ideas on how to get a Shiny App to use Packrat?

1,422 views
Skip to first unread message

Andrew Stewart

unread,
Mar 24, 2015, 2:00:22 PM3/24/15
to packrat...@googlegroups.com
I have a Shiny app with some package dependencies I was hoping to resolve via packrat (nothing too complicated here, just ggplo2; I just want to see how well this works).  I created the Shiny app within RStudio and opted to use Packrat with it, and then export the entire directory to a VM with a vanilla Shiny Server installation.  I was hoping that when the app was run it would detect packrat in the directory, but this does not seem to be the case. 

Any tips?  Is this not possible?

Joe Cheng

unread,
Mar 24, 2015, 3:37:58 PM3/24/15
to Andrew Stewart, packrat...@googlegroups.com
Can you try ssh-ing into the VM, going to the Shiny app directory, and starting R from there? I believe it should restore the packrat library automatically, but if not, try running packrat::restore().

On Tue, Mar 24, 2015 at 11:00 AM, Andrew Stewart <andrew.c...@gmail.com> wrote:
I have a Shiny app with some package dependencies I was hoping to resolve via packrat (nothing too complicated here, just ggplo2; I just want to see how well this works).  I created the Shiny app within RStudio and opted to use Packrat with it, and then export the entire directory to a VM with a vanilla Shiny Server installation.  I was hoping that when the app was run it would detect packrat in the directory, but this does not seem to be the case. 

Any tips?  Is this not possible?

--
You received this message because you are subscribed to the Google Groups "packrat-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packrat-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Stewart

unread,
Mar 24, 2015, 6:04:59 PM3/24/15
to packrat...@googlegroups.com, andrew.c...@gmail.com
(sorry if this is a re-post, it didn't look like my original reply sent)

Thanks Joe.

So the trick here is that I’m trying to do this completely non-interactively.  I want to script the whole deployment without any need to manually SSH in or start R (in interactive mode at least).

A little more background: I’m devising a way to very rapidly bundle and deploy self-sufficient Shiny apps within Docker containers.

Can I just untar the bundle in the App dir?  Or is the R process from Shiny not going to register packrat inside the App’s directory (since the R process presumably is executed outside of that dir)?

Joe Cheng

unread,
Mar 25, 2015, 12:35:07 AM3/25/15
to Andrew Stewart, packrat...@googlegroups.com
Can you just include in the Dockerfile the command to do the packrat restore--either as RUN or ONBUILD?

Andrew Stewart

unread,
Mar 25, 2015, 4:55:44 PM3/25/15
to Joe Cheng, packrat...@googlegroups.com
I believe so, but I’m unsure how to kickoff the restore from the command line.  I suppose I could do something along the lines of 

RUN Rbuild -e ‘packrat::restore()’ 

but im not sure that would trigger the bootstrap process?

Kevin Ushey

unread,
Mar 25, 2015, 5:05:01 PM3/25/15
to Andrew Stewart, Joe Cheng, packrat...@googlegroups.com
Assuming the R session is started within the same directory that the
project lives, that call should be able to restore successfully.
Alternatively, you can pass the project directory to the
`packrat::restore()` call, and that should be sufficient to rebuild
the project's private library (assuming it can find the
`packrat/packrat.lock` file)

You might instead want to use `packrat::init(project = "...")`, to
ensure the associated `.Rprofile` is also automagically generated (so
that R sessions started in that directory automatically use Packrat;
but note that this won't be the case if you launch R with e.g. `R
--vanilla`).

If you want to start an R session (shiny application) for a
packrat-powered project, you'll need to either:

1. Start the R session from the project directory with the
autoloader in the `.Rprofile` available, or
2. Start the R session, call `packrat::on(<projectDir>)`, and then
launch the application, or
3. Simply start R with the appropriate library path set on the
command line, e.g. `R_LIBS_USER=<privatePackratLibrary> R` -- assuming
you've already asked packrat to rebuild the private library with
`packrat::restore()`.

Hope this helps,
Kevin



On Wed, Mar 25, 2015 at 1:55 PM, Andrew Stewart

Andrew Stewart

unread,
Mar 25, 2015, 5:25:43 PM3/25/15
to Joe Cheng, packrat...@googlegroups.com
Thanks Joe.

So the trick here is that I’m trying to do this completely non-interactively.  I want to script the whole deployment without any need to manually SSH in or start R (in interactive mode at least).

A little more background: I’m devising a way to very rapidly bundle and deploy self-sufficient Shiny apps within Docker containers.

Can I just untar the bundle in the App dir?  Or is the R process from Shiny not going to register packrat inside the App’s directory (since the R process presumably is executed outside of that dir)?


Andrew Stewart

unread,
Mar 25, 2015, 8:35:41 PM3/25/15
to Kevin Ushey, Joe Cheng, packrat...@googlegroups.com
Great.  Thanks everyone.  I got this to work now.  Within the app directory under /srv/shiny-server I just copy the packrat bundle and then run the following empty R script to kick off the packrat bootstrap:  Rscript setup.R --bootstrap-packrat 

Doing so, I can bundle an entire Shiny app for deployment into a Docker container.  Very cool!

Doug Hayes

unread,
Aug 19, 2015, 9:25:50 AM8/19/15
to packrat-discuss, ke...@rstudio.com, j...@rstudio.com
Hi Andrew,

I am looking to do something similar and this sounds promising.  Do you have an example Dockerfile or example project on github somewhere so we can all take a look at your implementation? 

Thanks!
Reply all
Reply to author
Forward
0 new messages