2016-12-21 8 views
3

Githubにshinyjs、V8、dplyrなどのR/shinyプロジェクトがあり、コードにrequired(shinyjs)library(shinyjs)と指定しました。R Shiny requiredパッケージと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

これは正しい解決方法ですか? –

関連する問題