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

倾然丶 夕夏残阳落幕 提交于 2019-12-21 17:48:21

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/27397089/r-can-i-include-an-r-markdown-file-in-a-shiny-ui-r-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!