3

I am currently attempting to deploy a shiny app using a scheduled task on a windows machine. The idea is that a script runs each morning and aggregates data from several locations and then puts it into some R data.table objects for use in a shiny app.

I am using taskscheduleR to schedule the task. It initially sets the working directory to C:/Windows/system32 so I fix that to point to the directory where my application is located (C:/rprojects/myappname). The script runs fine until I attempt to deploy the file.

library(rsconnect)
deployApp(appName = "myappname", upload = TRUE, appFileManifest = "manifest.txt",account = "myaccountname", server = "shinyapps.io")

When I check the log from taskscheduleR I have the following lines

Preparing to deploy application...DONE
Uploading bundle for application: 999999...Error in contrib.url(getOption("repos"), type) : 
  trying to use CRAN without setting a mirror
Calls: deployApp ... withCallingHandlers -> <Anonymous> -> available.packages -> contrib.url
Execution halted

I've searched for the error message, and all I can find relates to setting the repo when using install.packages() which I don't use in my script. I expect it relates to how deployApp is attempting to find a URL however I can make sense of where I might need to (or be able to) declare the repository.

UPDATE (2016-10-11): I've activated a few options for rsconnect to get more detailed information on the deployment. Unfortunately it doesn't help provide any greater clarity.

options(rsconnect.http.trace = TRUE)
options(rsconnect.http.trace.json = TRUE)
options(rsconnect.http.verbose = TRUE)

Below is the output from the log

    GET /v1/applications/?filter=account_id:999999&filter=name:myappname&count=100&offset=0 1500ms
* Hostname was NOT found in DNS cache
*   Trying 54.225.182.222...
*   Trying 174.129.219.111...
* Connected to api.shinyapps.io (54.225.182.222) port 443 (#0)
  * successfully set certificate verify locations:
    *   CAfile: C:/RLibrary/rsconnect/cert/cacert.pem
  CApath: none
  * SSL connection using TLSv1.0 / ECDHE-RSA-AES128-SHA
  * Server certificate:
    *    subject: OU=Domain Control Validated; CN=*.shinyapps.io
  *      start date: 2016-07-18 14:17:38 GMT
  *      expire date: 2017-09-09 23:05:10 GMT
  *      subjectAltName: api.shinyapps.io matched
  *      issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority - G2
  *      SSL certificate verify ok.
  > GET /v1/applications/?filter=account_id:999999&filter=name:myappname&count=100&offset=0 HTTP/1.1
  User-Agent: rsconnect/0.4.3
  Host: api.shinyapps.io
  Accept: */*
    Date: Tue, 11 Oct 2016 01:26:02 GMT
  X-Auth-Token: xxxxxx
  X-Auth-Signature: xxxxxx; version=1
  X-Content-Checksum: xxxxxx

  < HTTP/1.1 200 OK
  < Content-Type: application/json; charset=UTF-8
  < Date: Tue, 11 Oct 2016 01:23:36 GMT
  < Etag: "xxxxxx"
  < Server: nginx/1.4.2
  < Content-Length: 3212
  < Connection: keep-alive
  < 
    * Connection #0 to host api.shinyapps.io left intact
  Error in contrib.url(getOption("repos"), type) : 
    trying to use CRAN without setting a mirror
  Calls: deployApp ... withCallingHandlers -> <Anonymous> -> available.packages -> contrib.url
  Execution halted
Dan
  • 2,625
  • 5
  • 27
  • 42
  • 1
    See if this helps http://stackoverflow.com/questions/17705133/package-error-when-running-r-code-on-command-line When you have `library(something)` in your code, the `deployApp` function will need to install the packages on the server if they are not installed, and that's where `install.packages` comes in. – Xiongbing Jin Oct 11 '16 at 00:19
  • As far as I can tell from the documentation of `rsconnect`, it looks for the `libraries` that are necessary for the shiny app and installs it on `shinyapps.io`. I may be missing something, but I would have thought the server is responsible for setting the repo. – Dan Oct 11 '16 at 01:34
  • I did update the `.rprofile` file to include a default `CRAN` mirror and it deploys fine. – Dan Oct 11 '16 at 03:13
  • What happens if you manually deploy the app to shinyapps.io, without using taskscheduleR – Xiongbing Jin Oct 11 '16 at 03:52
  • deploying from within RStudio works fine (from the deploy button, or with the command in the console). – Dan Oct 11 '16 at 03:53
  • I wonder if working directory should be the parent folder of your app, i.e. `c:/rprojects` – Xiongbing Jin Oct 11 '16 at 03:58
  • Given that it can deploy now with a minor change to the `.rprofile` file I am not inclined to worry to much more. If the working directory was the parent, then it would have issues picking up files with `source()`. – Dan Oct 11 '16 at 04:01

1 Answers1

3

set

options(repos = c(CRAN = "https://cran.rstudio.com/")) 

somewhere at the top of your script which you wanted to launch with taskscheduleR If you launch R with Rscript, the CRAN repository is not set, which is different then if you run your code in the RStudio editor.