title: shinyApp not rendering Rmarkdown file as RStudio
body: <p>I'm struggling to understand why shinyApp does not render a Rmarkdown file as done by RStudio, even when Rmarkdown is explicitly defined in app.R.</p>
  
  <p>The Rmd file below has been written in RStudio, and when the "Run document" button is clicked an HTML document is generated with a friendly web of the application, the sidebar, pages, and plots. However, if this is hosted together with an <strong>app.R</strong> file in shiny-server, some errors are returned and the file rendered lacks of the structure of the original document (eg. sidebar, pages, etc..). This can be generated also by running <code>Rscript --vanilla app.R</code> and going to <code>localhost:port</code>.</p>
  
  <p>Here are the files I'm using:</p>
  
  <p><strong>example.Rmd</strong></p>
  
  <pre><code>---
  title: "Example file"
  runtime: shiny
  theme: simplex
  vertical_layout: fill
  output:
    flexdashboard::flex_dashboard:
      orientation: rows
  ---
  
  ```{r setup, include=FALSE}
  library(shiny)
  library(tidyverse)
  library(plotly)
  ```
  
  Sidebar {.sidebar}
  ======================================================================
  
  **Options**
  
  ```{r opt_general, echo = FALSE}
  selectInput("opt_cyl",
              label = "Select cyl",
              choices = mtcars %&gt;% .$cyl %&gt;% unique %&gt;% sort,
              multiple = TRUE,
              selected = "4")
  
  sliderInput("opt_qsec", label = "Qsec", min = mtcars$qsec %&gt;% min, max = mtcars$qsec %&gt;% max, value = mtcars$qsec %&gt;% max, step = 0.01)
  ```
  
  **More options**
  
  ```{r opt_dist, echo = FALSE}
  checkboxInput("opt_log", label = "Log scale (qsec)", value = FALSE)
  ```
  
  Explore
  ======================================================================
  
  ```{r global, echo=FALSE}
   mtcars$cyl &lt;- as.character(mtcars$cyl)
   ```
  
   ```{r reactive_global, echo=FALSE}
  rcars &lt;- reactive({
     C &lt;- dplyr::filter(mtcars, cyl==input$opt_cyl, qsec &lt;= input$opt_qsec)
    return(C)
  })
   ```
  
  Row
  ------------------------
  
  ### One nice plot
  
  ```{r plot1a, echo = FALSE}
      uiOutput("r1a")
  
  output$r1a &lt;- renderUI({
    plotlyOutput("p1a")
  })
  
  output$p1a &lt;- renderPlotly({
    P &lt;- mtcars %&gt;% ggplot() + geom_point(aes(x=cyl, y=qsec))
    ggplotly(P)
  })
  ```
  
  ### Another nice plot
  
  ```{r plot1b, echo = FALSE}
  uiOutput("r1b")
  
  output$r1b &lt;- renderUI({
    plotlyOutput("p1b")
  })
  
  output$p1b &lt;- renderPlotly({
    P &lt;- rcars() %&gt;% ggplot() + geom_point(aes(x=cyl, y=qsec))
    ggplotly(P)
  })
  ```
  
  Row
  ------------------------
  
  ### Second row plot
  
  ```{r plot2, echo = FALSE}
  uiOutput("r2")
  
  output$r2 &lt;- renderUI({
    plotlyOutput("p2")
  })
  
  output$p2 &lt;- renderPlotly({
    C &lt;- rcars()
    if (input$opt_log) C$qsec &lt;- log(C$qsec)
    P &lt;- C %&gt;% ggplot() + geom_point(aes(x=mpg, y=qsec))
    ggplotly(P)
  })
  ```
  
  About
  ======================================================================
  
  Some nice README
  </code></pre>
  
  <p>The corresponding <strong>app.R</strong> file is:</p>
  
  <pre><code>library(shiny)
  library(knitr)
  
  ui &lt;- shinyUI(
    fluidPage(
      uiOutput('markdown')
    )
  )
  
  server &lt;-function (input, output) {
    output$markdown &lt;- renderUI({
      HTML(markdown::markdownToHTML(knit('example.Rmd', quiet = TRUE)))
    })
  }
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>The error returned in the log file is:</p>
  
  <blockquote>
    <p>Listening on <a href="http://127.0.0.1:44229" rel="nofollow noreferrer">http://127.0.0.1:44229</a>
    Warning: Error in : Result must have length 32, not 0
      125: 
    Warning: Error in : Result must have length 32, not 0
      100: </p>
  </blockquote>
  
  <p>Does someone can give me a pointer on why this is happening? Thank you</p>