2017-07-27 35 views
1

我有一個閃亮的應用程序,我希望每個人都可以使用runGitHub運行,並且只安裝閃亮的軟件包。在Shiny應用程序中安裝必需的軟件包

爲了安裝並在聯絡人的電腦,他運行的程序第一次加載所有所需的軟件包,我在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) 

儘管如此,我只是測試它在別人的電腦,以下錯誤顯示出來:

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") 

回答

2

有機會,該packages可能與它一起的一些dependencies,因此與依賴的所有軟件包需要安裝。爲了解決每個新用戶的問題,您可以像這樣執行檢查和安裝(如有必要)。

#list of packages required 
list.of.packages <- ("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) 

希望這會有所幫助。

0

這個工作對我來說:

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

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