3

I would like to deploy a shiny app to shinyapps.io but I keep failing to publish it all in all for several months now :-(

Could someone please explain to me step-by-step what I need to do for the specific setup outlined below?

Setup

  • the app depends on a custom package that lives in a private GitHub repo
  • I do not have a full-fledged R package repo that is accessible by RStudio Connect in order to install the custom package but would like to install it from GitHub
  • a .Rprofile file lives in the root directory of the project that I'm trying to publish and it contains
local({
  r <- getOption("repos")
  r["CRAN"] <- "https://cran.rstudio.com/"
  r["mycompany"] <- "https://github.com/rappster/mypkg/"
  options(repos = r)
})
  • the tar.gz build of the custom package lives in /opt/r-packages/<pkg-name>/<git-commit-hashkey>.tar.gz
  • a gcfg file lives in /etc/rstudio-connect/rstudio-connect.gcfg and it only contains SourcePackageDir = "opt/r-packages"
  • the custom package has itself a number of dependencies that are all available on CRAN
  • the code for the shiny app lives in several files in the root dir of the project which currently corresponds to the custom's package project (since I thought this would be the easiest to make publishing work), but I could also put it in its own RStudio/R project if that would help

Due diligence

I've read

but wasn't able to get things working.

RStudio Connect deployment error that I'm getting

<...>
[2019-02-05T11:50:16.877574592+0000] Building R package: mypkg (0.0.2.9002)
/mnt/packages/build /mnt
Warning in untar2(tarfile, files, list, exdir, restore_times) :
  skipping pax global extended headers
* installing to library ‘/opt/R/3.5.1/lib/R/library’
* installing *source* package ‘mypkg’ ...
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called ‘philentropy’
ERROR: lazy loading failed for package ‘climater’
* removing ‘/opt/R/3.5.1/lib/R/library/mypkg’GET /v1/tasks/?filter=account_id:113102&filter=parent_id:584709513&count=100&offset=0 590ms
################################# End Task Log ################################# 
----- Deployment error -----
Error: Unhandled Exception: Child Task 584709513 failed: Error building image: Error building mypkg (0.0.2.9002). Build exited with non-zero status: 1

----- Error stack trace -----
3: stop(status$error, call. = FALSE)
2: client$waitForTask(taskId, quiet)
1: rsconnect::deployApp(appDir = "C:/Users/janko/Dropbox (Personal)/Code/R/Packages/_Dev/mypkg", 
       appFileManifest = "C:/Users/janko/AppData/Local/Temp/6d2a-63b4-2877-4884", 
       account = "janko-thyson", server = "shinyapps.io", appName = "mypkg", 
       appId = 585041, launch.browser = function(url) {
           message("Deployment completed: ", url)
       }, lint = FALSE, metadata = list(asMultiple = FALSE, asStatic = FALSE, 
           ignoredFiles = <...>), 
       logLevel = "verbose")
Error: Unhandled Exception: Child Task 584709513 failed: Error building image: Error building mypkg (0.0.2.9002). Build exited with non-zero status: 1
Execution halted

Does that mean I need to build all of my package's dependencies and also put it under opt/<pkg-dependency-name>/<git-commit-hashkey>.tar.gz?

Sorry in case this is a duplicate or seems to be a bit unstructured/verbose, but my head is completely swirling trying to get this to work and I have no clue where to start with troubleshooting...

Rappster
  • 12,762
  • 7
  • 71
  • 120
  • 1
    Did you ever figure this out? I am also trying to install a package Shiny app on shinyapps.io. It depends on 2 packages only on GitHub. I get the same issue as you. – msm1089 Nov 03 '21 at 22:48
  • The error in you log, shows that a couple packages are not in your NAMESPACE. You should review the source code for "mypkg" and: include `import(philentropy)` in your NAMESPACE file ; consider also to add `Depends: philentropy` in your DESCRIPTION file. – David Martinez C. Jul 27 '22 at 23:16

2 Answers2

0

Deploy shiny app using custom package with RStudio

  • Use renv in your app project
  • Generate a personal access token in GitHub
  • Modify the .Rprofile (is in your project directory) to show this:
source("renv/activate.R")
local({
  r <- getOption("repos")
  r["CRAN"] <- "https://cran.rstudio.com/"
  r["mycompany"] <- "https://github.com/<your_user>/<your_repo>/"
  options(repos = r)
})
  • Within your project, open the R terminal and install your package:
devtools::install_github("<my_user>/<my_repo>",
    auth_token = "<paste_your_token_here>",
    upgrade = "never") #this is optional, 
# but since you are using renv, you may want to conserve 
# your environment

This will install your package in the renv

IMPORTANT: don't include the previous line in the source code you're going to upload to shiny.io or similar Read about it

  • Publish your app.

After you've done this, rsconnect should be able to read your packages from your source code and upload them from your renv. Actually, the first time shiny.io build my package, there was a time out and didn't upload the app. But, it installed my custom package in its environment and the second time I tried to upload the app, it worked.

NOTE: In my case, my package was in a public github repository. Haven't tried with private repos, but I know there's an option in shiny.io that connects the server to the private repositories. I think you will also need to configure your personal access token so it can be use to read private repos.

0

I'm not sure if this would equally work for a private repo but, to use a public GitHub repo, just simply:

  1. Unload the package:
detach("package:mypkg", unload = TRUE)
  1. Reinstall the package from GitHub on your local machine:
devtools::install_github("https://github.com/myorg/mypkg", upgrade = TRUE)
  1. Click publish.

Shiny will figure out the rest.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83