繁体   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