I have trying to run Shiny from the command line but am unable to. I have created a demo shiny file the command I have tried to use and the error I get below:
---
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
)
```
The command to run the script is:
Rscript -e "rmarkdown::run('"D:/Test/testrmd.Rmd"', shiny_args = list(launch.browser = TRUE))"
which is run from the command line
I get the error:
Error in loadNamespace(x) : there is no package called 'rmarkdown' Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted
CodePudding user response:
First make sure rmarkdown package is installed. Then try this -
Rscript -e "library(rmarkdown); rmarkdown::run('"D:/Test/testrmd.Rmd"', shiny_args = list(launch.browser = TRUE))
If error perists, try install.packages("rmarkdown")
and then run the above step
CodePudding user response:
Your code file doesn't have any R shiny code, this is just an Rmarkdown file. Flexdashboard can use shiny, but doesn't have shiny by default. you need runtime: shiny
(as well as the Rmarkdown package) to utilize the shiny functionality. Then for me, I opened my terminal to the directory where my .Rmd file was saved and ran what John and you suggested, but I am on Mac so it was a little different Rscript -e "rmarkdown::run('delete.Rmd', shiny_args=list(launch.browser=TRUE))"
... which rendered the Rmd file and automatically launched the browser with the HTML file, awesome!
---
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
)
```