Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Can I include an R markdown file in a shiny ui.R file?

Tags:

r

knitr

shiny

I refer to the code example at http://shiny.rstudio.com/gallery/including-html-text-and-markdown-files.html. In my case I would like to include and R markdown file rather than a markdown.

The following is my code for ui.R

library(markdown)
shinyUI(fluidPage(

    titlePanel("Tourist expenditure for the year 2012 in Malta"),

    fluidRow(
        column(2,
               checkboxGroupInput("id1", "Analyse by",
                                  c("Sex" = "1",
                                    "Age Group" = "2")
         )),
        column(6,
               h4('You entered'),
               verbatimTextOutput("oid1")
        ),
        column(4,
               includeMarkdown("intro.Rmd")
        )
    )
))

My problem is that intro.Rmd is not compiling when embedded in shinyUI but works as expected when I choose the Knit HTML option.

Is there a way I can insert the Rmd source file directly.

Thanks.

like image 419
chribonn Avatar asked Dec 10 '14 09:12

chribonn


1 Answers

I've had similar problems in the past, and know of two solutions:

  1. pre-compile the .Rmd file and include the markdown or HTML using the functions you've mentioned.

  2. call knitr from shiny within the server.R file (if the document changes due to the shiny app) and then include the compiled HTML/markdown code with includeHTML() or a similar function.

like image 66
srvanderplas Avatar answered Oct 23 '22 16:10

srvanderplas