8

I have a flexdashboard Rmd that renders correctly when i press the Knit button in RStudio. I would like to render it from the command line but the naviagation bar does change when I use the command render("myfile.rmd", flex_dashboard())

The heading of my Rmd file is the following:

---
title: "Flexdashboard"
output: 
  flexdashboard::flex_dashboard:
      theme: cosmo
      navbar:
      - { title: "Draft-For Internal Use Only", align: right }
      source_code: embed
---
rjss
  • 935
  • 10
  • 23

3 Answers3

10

You can call render with no arguments and it will pick up all of the options in YAML:

render("myfile.Rmd")

Altons was correct that using flex_dashboard() creates a new format that uses all the defaults. To render a format and keep the settings from YAML you use:

render("myfile.Rmd", "flex_dashboard")

But this latter form is only required if flex_dashboard isn't already the default format within the Rmd.

JJ Allaire
  • 556
  • 3
  • 3
4

pass arguments within the flex_dashboard().

For example:

render("myfile.rmd", flex_dashboard(theme=simplex),output='myfile_html')
Altons
  • 1,422
  • 3
  • 12
  • 23
  • I saw that I can pass arguments to `flex_dashboard ` but since these are defined in the YAML of the file; is there a way to read them directly? – rjss Aug 08 '16 at 13:57
  • I presume title and author are picked up correclty? I had similar issue, it seems like render only picks the 1st level of YAML header and omit the rest - maybe a bug? I added them to render and also left them in the .Rmd in case I need to run the knit button. it works fine – Altons Aug 08 '16 at 14:45
  • 2
    Giving it more thoughts maybe the `flex_dashboard()` from render overwrites the YAML options.... just a thought – Altons Aug 08 '16 at 14:48
3

FWIW, and to prevent people from saying, wait, what's render? Why can't I use knit?.... o ok, so why can't I then use knit2html? These are the steps to render a flexdashboard from the command line:

  1. Install Pandoc

  2. Close your current cmd if you haven't already.

  3. Run this command: "C:\Program Files\R\R-3.2.2\bin\x64\R.exe" -e "rmarkdown::render('C:/FULLPATH/myFlexDashboard.Rmd')"

  4. If it works, put that in a .bat file and celebrate!

(for step 3, note the slashes/backslashes... they should be exactly like that, but your R version might be different)

Amit Kohli
  • 2,860
  • 2
  • 24
  • 44