I am trying to use r markdown to generate a HTML document for presentation. Now when I do it using standalone that seems to be working fine. But when I use it in a shiny app that doesnt seem to be working. So far I have used this in UI
includeHTML("mkslides.html")
And in the server used this to render the markdown.
out <- render('mkslides.Rmd')
The markdown seems to be rendered when I see the console while the shiny app loads. But all I see is the HTML file without the css and js required. How can I fix this?
To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.
There are two types of output formats in the rmarkdown package: documents, and presentations.
There are two ways to render an R Markdown document into its final output format. If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it. Note that both methods use the same mechanism; RStudio's “Knit” button calls rmarkdown::render() under the hood.
There are two ways to do this: Defining the application inline using the shinyApp() function; or. Referring to an external application directory using the shinyAppDir() function.
I'm not 100% sure of your objective, so will try address two points above.
- Rendering HTML documents in a
ShinyApp
This is pretty straightforward, all you need to do is use includeHTML
in your UI.R
portion of your ShinyApp, no server side component is required.
http://shiny.rstudio.com/gallery/including-html-text-and-markdown-files.html
Note: includeHTML
does not render your *.Rmd
file.
- Rendering a .Rmd file in a
ShinyApp
This requires knit
and markdownToHTML
, see the below thread.
RMarkdown in Shiny Application
Example .Rmd file
---
title: "An example Knitr/R Markdown document"
output: html_document
---
{r chunk_name, include=FALSE}
x <- rnorm(100)
y <- 2*x + rnorm(100)
cor(x, y)
{r scatterplot, fig.width=8, fig.height=6}
plot(x,y)
Above saved as:
test_presentation.Rmd
andknit
as atest_presentation.html
1. Include the HMTL
file in Shiny
library(shiny)
ui <- shinyUI(
fluidPage(
includeHTML('test_presentation.html')
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
2. Render the above *.Rmd
file in Shiny
Code taken form: https://stackoverflow.com/a/33500524/5996972
library(shiny)
library(knitr)
ui <- shinyUI(
fluidPage(
uiOutput('markdown')
)
)
server <- function(input, output) {
output$markdown <- renderUI({
HTML(markdown::markdownToHTML(knit('test_presentation.rmd', quiet = TRUE)))
})
}
shinyApp(ui, server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With