简体   繁体   English

R:我可以在闪亮的ui.R文件中包含R markdown文件吗?

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

I refer to the code example at http://shiny.rstudio.com/gallery/including-html-text-and-markdown-files.html . 我参考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. 在我的情况下,我想包括和R markdown文件而不是降价。

The following is my code for ui.R 以下是我的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. 我的问题是intro.Rmd在嵌入shinyUI时没有编译,但是在我选择Knit HTML选项时按预期工作。

Is there a way I can insert the Rmd source file directly. 有没有办法可以直接插入Rmd源文件。

Thanks. 谢谢。

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. 预编译.Rmd文件并使用您提到的功能包含markdown或HTML。

  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. 在server.R文件中调用knitr(如果文档由于闪亮的应用程序而发生变化),然后使用includeHTML()或类似函数包含已编译的HTML / markdown代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM