【问题标题】:R Shiny required packages and GithubR Shiny 所需的软件包和 Github
【发布时间】:2017-05-06 19:08:16
【问题描述】:

所以我在 Github 上有一个 R/shiny 项目,它需要一些包,例如 shinyjs、V8 和 dplyr,并且我在代码中指定了 required(shinyjs)library(shinyjs)

在我的电脑上它工作得很好,如果我从 Github 下载一个也可以工作的副本,但如果我从另一台电脑上下载,我必须手动下载所需的包。

有没有办法让 Rstudio 在有人尝试运行应用程序时自动安装所需的包?

【问题讨论】:

  • 我们将不胜感激。

标签: r github shiny rstudio


【解决方案1】:

这样做。功能在这里: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")
    })
  }
)

加载中:

应用:

产量:

【讨论】:

    猜你喜欢
    • 2014-02-25
    • 2017-01-06
    • 2012-06-20
    • 2019-07-21
    • 2020-11-24
    • 2019-03-05
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多