[英]R Shiny required packages and Github
So I have a R/shiny project on Github that require some packages, for example shinyjs, V8 and dplyr, and I have specified required(shinyjs)
and library(shinyjs)
in the code. 所以我在Github上有一个R / shiny项目需要一些软件包,比如shinyjs,V8和dplyr,我在代码中指定了
required(shinyjs)
和library(shinyjs)
。
On my computer it works just fine and if I download a copy from Github that works too, but if I do it from a different computer I have to download the packages required manually. 在我的计算机上它工作正常,如果我从Github下载副本也可以,但如果我从另一台计算机上下载,我必须手动下载所需的软件包。
Is there a way to make Rstudio install the required packages automatically when someone tries to run the application? 当有人试图运行应用程序时,有没有办法让Rstudio自动安装所需的包?
This does that. 这样做。 Got the function here: malonypatr's install_load function
得到了这里的功能: malonypatr的install_load函数
The screenshots are from RTVS, but I tested it in R-Studio too. 截图来自RTVS,但我也在R-Studio中测试过它。
library(shiny)
install_load <- function (package1, ...) {
# convert arguments to vector
packages <- c(package1, ...)
# start loop to determine if each package is installed
for(package in packages){
# if package is installed locally, load
if(package %in% rownames(installed.packages()))
do.call('library', list(package))
# if package is not installed locally, download, then load
else {
install.packages(package)
do.call("library", list(package))
}
}
}
install_load("shinyjs")
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
# Add a CSS class for red text colour
inlineCSS(list(.red = "background: red")),
actionButton("btn", "Click me"),
p(id = "element", "Watch what happens to me")
),
server = function(input, output) {
observeEvent(input$btn, {
# Change the following line for more examples
toggleClass("element", "red")
})
}
)
Loading: 加载:
Yielding: 产量:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.