Skip to content

Instantly share code, notes, and snippets.

@daroczig
Created June 29, 2015 11:32
Show Gist options
  • Save daroczig/2812971d0c2613ceb669 to your computer and use it in GitHub Desktop.
Save daroczig/2812971d0c2613ceb669 to your computer and use it in GitHub Desktop.
Markdown preview via shiny, pandoc and rmarkdown
library(shiny)
library(rmarkdown)
shinyServer(function(input, output) {
output$html = reactive({
t <- tempfile()
cat(input$markdown, file = t)
## convert input to html
t <- render(
input = t,
output_format = 'html_document')
## read results
res <- readLines(t)
## cleanup
unlink(sub('.html$', '*', t))
## return
paste(res, collapse = '\n')
})
})
library(shiny)
shinyUI(fluidPage(
titlePanel('Try markdown'),
fluidRow(
column(6,
tags$textarea(
'Hello markdown!',
id = 'markdown',
rows = 25,
style = 'width:100%;')),
column(6,
htmlOutput('html')))
))
@daroczig
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment