2017-07-27 134 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))