簡體   English   中英

如何在 shiny 應用程序中使用 renv package 以避免在 shiny 服務器上安裝新包?

[英]How to use renv package in shiny app to avoid installing new packages on shiny server?

我想為 shiny 應用程序測試renv package。 這是我的虛擬應用程序:

library(pool)
library(fresh)
library(shiny)


ui <- fluidPage(
    titlePanel("Old Faithful Geyser Data"),
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        mainPanel(
           plotOutput("distPlot")
        )
    )
)
server <- function(input, output) {

    output$distPlot <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}
shinyApp(ui = ui, server = server)

請注意,我只加載了 2 個庫poolfresh沒有使用它們。 來自renv package 的init()命令正在我的項目路徑上創建一個本地庫:

renv::init("/home/z0044uca/mytest_renv/") 

* Initializing project ...
* Discovering package dependencies ... Done!
* Copying packages into the cache ... [21/21] Done!
The following package(s) will be updated in the lockfile:

# CRAN ===============================
- BH            [* -> 1.72.0-3]
- R6            [* -> 2.4.1]
- Rcpp          [* -> 1.0.5]
- base64enc     [* -> 0.1-3]
- commonmark    [* -> 1.7]
- crayon        [* -> 1.3.4]
- digest        [* -> 0.6.25]
- fastmap       [* -> 1.0.1]
- glue          [* -> 1.4.2]
- htmltools     [* -> 0.5.0]
- httpuv        [* -> 1.5.4]
- jsonlite      [* -> 1.7.1]
- later         [* -> 1.1.0.1]
- magrittr      [* -> 1.5]
- mime          [* -> 0.9]
- promises      [* -> 1.1.1]
- renv          [* -> 0.12.5]
- rlang         [* -> 0.4.7]
- shiny         [* -> 1.5.0]
- sourcetools   [* -> 0.1.7]
- withr         [* -> 2.2.0]
- xtable        [* -> 1.8-4]

* Lockfile written to '~/mytest_renv/renv.lock'.
* Project '~/mytest_renv' loaded. [renv 0.12.5]

Restarting R session...

* Project '~/mytest_renv' loaded. [renv 0.12.5]

我的問題是如何將應用程序部署到我的閃亮服務器而不在服務器上安裝兩個包( poolfresh )。

當我將整個文件夾( mytest_renv )復制到我的服務器並嘗試在瀏覽器中運行該應用程序時,我收到以下錯誤(在log文件中)

Warning message:
The following package(s) are missing entries in the cache:

        base64enc, BH, commonmark, crayon, DBI, digest, fastmap,
        fresh, fs, glue, htmltools, httpuv, jsonlite, later,
        magrittr, mime, pool, promises, R6, rappdirs, Rcpp, rlang,
        rstudioapi, sass, shiny, sourcetools, withr, xtable

These packages will need to be reinstalled.

Error in loadNamespace(name) : there is no package called ‘digest’
Calls: local ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted

我期待我的應用程序目錄中的renv文件夾負責所有的包和依賴項。

https://community.rstudio.com/t/shiny-server-renv/71879/2可能是相關的——您可能想在復制項目文件夾之前調用renv::isolate()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM