簡體   English   中英

在Shiny應用程序中安裝所需的軟件包

[英]Installing required packages in Shiny app

我有一個閃亮的應用程序,我希望每個人都可以使用runGitHub來運行,並且具有安裝閃亮包裝的唯一先決條件。

為了在他第一次運行該程序時將所有必需的軟件包安裝和加載到計算機中,我在server.R中的代碼以以下代碼開頭:

if (!require("pacman")) install.packages("pacman")
pacman::p_load("maptools","dplyr","data.table","reshape2","ggplot2","plyr","rgdal","rgeos","shinyjs","scales","DT","readxl")

library(maptools)
library(dplyr)
library(data.table)
library(reshape2)
library(ggplot2)
library(plyr)
library(rgdal)
library(rgeos)
library(shinyjs)
library(scales)
library(DT)
library(readxl) 

但是,我只是在其他人的PC上對其進行了測試,並顯示以下錯誤:

Error in library(shinyjs) : there is no package called ‘shinyjs’

在我手動安裝了Shinyjs之后,出現了以下內容:

Warning: Error in library: there is no package called ‘maptools’
Stack trace (innermost first):
46: library
45: eval [helper.R#1]
44: eval
43: withVisible
42: source
 3: runApp
 2: runUrl
 1: runGitHub
Error in library(maptools) : there is no package called ‘maptools’

等等。 這是我的第一個閃亮的應用程序,所以我不知道該怎么實現。 通過運行以下命令可以訪問我的完整代碼:

runGitHub("Mapas_BBVA_municipios","IArchondo",display.mode="showcase") 

這些packages可能會與之同時具有某些dependencies ,因此需要安裝所有具有依賴性的軟件包。 要為每個新用戶解決此問題,您可以像這樣執行檢查和安裝(如有必要)。

#list of packages required
list.of.packages <- c("pacman","maptools","dplyr","data.table","reshape2","ggplot2","plyr","rgdal","rgeos","shinyjs","scales","DT","readxl")

#checking missing packages from list
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]

#install missing ones
if(length(new.packages)) install.packages(new.packages, dependencies = TRUE)

希望這可以幫助。

這對我有用:

list_of_packages = c("ggplot2","pacman")

lapply(list_of_packages, 
       function(x) if(!require(x,character.only = TRUE)) install.packages(x))

暫無
暫無

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

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