Error when trying to deploy to shinyapps.io: Application depends on package “package” but it is not

后端 未结 1 1084
后悔当初
后悔当初 2020-12-19 15:46

My server.R contains the following code for dynamically installing packages when needed:

package <- input$chip
if (!require(package, character.only=T, qui         


        
相关标签:
1条回答
  • 2020-12-19 16:22

    Unfortunately, you have to fool the shinyapps (or rsconnect) package a bit so that it does not detect package as a literal package name. For example, you may use do.call():

    do.call(library, list(package = package, character.only = TRUE))
    

    The ShinyApps.io server does not allow you to install packages on the fly (strictly speaking, this is not true, but I don't want to show you how). You have to declare all packages you need in the app as dependencies beforehand. Again, it is a hack:

    if (FALSE) {
      library(mogene10sttranscriptcluster.db)
      library(mogene20sttranscriptcluster.db)
      library(hugene10sttranscriptcluster.db)
      library(hgu133a2.db)
    }
    

    Then ShinyApps.io will detect these packages as dependencies and pre-install them for you. What you need to do in your app is simply load them, and you don't need to install them by yourself.

    0 讨论(0)
提交回复
热议问题