【问题标题】:Unable to run R Shiny in command line无法在命令行中运行 R Shiny
【发布时间】:2021-11-22 08:04:55
【问题描述】:

我试图从命令行运行 Shiny,但无法运行。我已经创建了一个演示闪亮文件,我尝试使用的命令和我得到的错误如下:

---
title: "Test"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
```

```{r plot1}
ggplot(mpg, mapping = aes(x = displ, y = hwy)) +
  geom_point(mapping = aes(color = class)) +
  geom_smooth(
  data = filter(mpg, class == "subcompact"),
  se = FALSE
)
```

运行脚本的命令是: Rscript -e "rmarkdown::run('"D:/Test/testrmd.Rmd"', shiny_args = list(launch.browser = TRUE))" 从命令行运行

我得到错误:

Error in loadNamespace(x) : there is no package called 'rmarkdown' Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted

【问题讨论】:

  • 你安装了 rmarkdown 包吗?看起来不像

标签: r shiny command-line r-markdown


【解决方案1】:

您的代码文件没有任何 R 闪亮代码,这只是一个 Rmarkdown 文件。 Flexdashboard 可以使用闪亮,但默认情况下没有闪亮。您需要 runtime: shiny(以及 Rmarkdown 包)来利用闪亮的功能。然后对我来说,我打开我的终端到保存我的 .Rmd 文件的目录并运行 John 和你建议的内容,但我在 Mac 上,所以它有点不同 Rscript -e "rmarkdown::run('delete.Rmd', shiny_args=list(launch.browser=TRUE))"... 它呈现 Rmd 文件并自动用 HTML 文件启动浏览器,太棒了!

---
title: "Test"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(rmarkdown)
```

```{r plot1}
ggplot(mpg, mapping = aes(x = displ, y = hwy)) +
  geom_point(mapping = aes(color = class)) +
  geom_smooth(
  data = filter(mpg, class == "subcompact"),
  se = FALSE
)
```

【讨论】:

  • 这有帮助!我实际上意识到我还必须在环境变量中设置 .libPaths 才能使命令正常工作。
【解决方案2】:

首先确保已安装 rmarkdown 软件包。然后试试这个 -

Rscript -e "library(rmarkdown); rmarkdown::run('"D:/Test/testrmd.Rmd"', shiny_args = list(launch.browser = TRUE))

如果错误仍然存​​在,请尝试install.packages("rmarkdown"),然后运行上述步骤

【讨论】:

  • Rmarkdown 已安装
猜你喜欢
  • 2019-03-05
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
  • 1970-01-01
  • 2021-11-12
  • 2018-01-30
  • 2020-12-20
  • 1970-01-01
相关资源
最近更新 更多