2016-12-21 46 views
3

所以我在Github上有一個需要一些軟件包的R/shiny項目,例如shinyjs,V8和dplyr,並且我在代碼中指定了required(shinyjs)library(shinyjs)R Shiny所需的軟件包和Github

在我的電腦它工作得很好,如果我從Github上下載一個副本的作品太多,但如果我從不同的計算機做我必須手動下載所需的軟件包。

有沒有一種方法,使Rstudio自動安裝所需的軟件包,當有人試圖運行應用程序?

+0

反饋,將不勝感激。 –

回答

2

這做到這一點。在這裏得到了功能:malonypatr's install_load function

屏幕截圖來自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") 
    }) 
    } 
) 

加載:

enter image description here 應用:

產量:我的答案

enter image description here

+0

那麼這是一個正確的解決方案? –