R Shiny 所需的包和 Github

标签 r github shiny rstudio

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

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

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

最佳答案

这样做。在此处获得功能: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

关于R Shiny 所需的包和 Github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41261429/

相关文章:

r - 层次聚类大稀疏距离矩阵R

r - 如何将结果存储在for循环的列表中

r - 数据集中每组的样本数不同

java - 从 GitHub 项目导出可用的 .jar 文件

html - Shiny 的仪表板 : jump to specific element in app by clicking infoBox

mysql - 标准无歧义格式 [R] MySQL 导入数据

git - 如何从 github 中的不同分支 merge

java - GitHub 上托管的 maven 项目的 groupId

r - HTTPS 用于 Shiny 的应用程序?

drop-down-menu - 允许在 Rhandsontable 列下拉列表中进行多选