-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.R
99 lines (82 loc) · 2.63 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
library(knitr)
library(rsconnect)
library(shiny)
library(shinyAce)
library(rmarkdown)
# Default text for editor
defaultMarkdown <- '
---
title: "Sample R Markdown Doc"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
'
#' A Shiny UI for editing R Markdown
ui <- shinyUI(
bootstrapPage(
headerPanel("Embedded Deployment Example"),
div(
class="container-fluid",
div(class="row-fluid",
div(class="col-sm-6",
h2("Source R-Markdown"),
aceEditor("rmd", mode="markdown", value=defaultMarkdown),
textInput("appName", "Doc Name", value = "GeneratedDoc"),
textInput("user", "Connect User", value = "admin"),
textInput("server", "Connect Server Name", value = "mytestserver"),
actionButton("eval", "Update Output"),
actionButton("deploy", "Deploy Output")
),
div(class="col-sm-6",
h2("Knitted Output"),
htmlOutput("knitDoc")
)
)
)
)
)
#' A Shiny application that generates and deploys R Markdown content
server <- shinyServer(function(input, output, session) {
# Render the doc when the 'Update' button is clicked
rmd <- eventReactive(input$eval, {
input$rmd
})
# Deploy the doc when the 'Deploy' button is clicked
observeEvent(input$deploy, {
options(repos=c(CRAN="https://cran.rstudio.com"))
tryCatch({
rsconnect::deployDoc(doc="out.Rmd", appName=input$appName, account=input$user, server=input$server)
},
error=function(e) {
message("", e)
})
})
output$knitDoc <- renderUI({
writeLines(rmd(), "out.Rmd")
result <- "error"
tryCatch({
knit2html(input="out.Rmd", fragment.only = TRUE, quiet = TRUE)
result <- isolate(HTML(readLines("out.html")))
},
error=function(e) {
message("", e)
})
result
})
})
# Run the application
shinyApp(ui = ui, server = server)