Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. library(shiny)
  2. library(rmarkdown)
  3. library(htmltools)
  4. library(knitr)
  5. shinyServer(function(input, output) {
  6.  
  7. output$distPlot <- renderPlot({
  8.  
  9. # generate bins based on input$bins from ui.R
  10. x <- faithful[, 2]
  11. bins <- seq(min(x), max(x), length.out = input$bins + 1)
  12.  
  13. # draw the histogram with the specified number of bins
  14. hist(x, breaks = bins, col = 'darkgray', border = 'white')
  15.  
  16. })
  17. output$Generate_PDF_Document <- downloadHandler(
  18.  
  19. # For PDF output, change this to "report.pdf"
  20. filename = paste0("Highchart Document",format(Sys.Date(),"%d%m%Y"),".html"),
  21. content = function(file) {
  22. # # Copy the report file to a temporary directory before processing it, in
  23. # # case we don't have write permissions to the current working dir (which
  24. # # can happen when deployed).
  25. tempReport <- normalizePath('Test.Rmd')
  26. file.copy(tempReport, "Test.Rmd", overwrite = FALSE)
  27.  
  28.  
  29. # Knit the document, passing in the `params` list, and eval it in a
  30. # child of the global environment (this isolates the code in the document
  31. # from the code in this app).
  32. out <- render('Test.Rmd', html_document())
  33. file.rename(out,file)
  34. })
  35.  
  36. })
  37.  
  38. library(shiny)
  39.  
  40. shinyUI(fluidPage(
  41.  
  42. # Application title
  43. titlePanel("Old Faithful Geyser Data"),
  44.  
  45. # Sidebar with a slider input for number of bins
  46. sidebarLayout(
  47. sidebarPanel(
  48. sliderInput("bins",
  49. "Number of bins:",
  50. min = 1,
  51. max = 50,
  52. value = 30)
  53. ),
  54.  
  55. # Show a plot of the generated distribution
  56. mainPanel(
  57. plotOutput("distPlot"),
  58. downloadButton('Generate_PDF_Document','Generate a PDF Report')
  59. )
  60. )
  61. ))
  62.  
  63. ---
  64. title: "Test"
  65. output:
  66. html_document:
  67. toc: true
  68. toc_depth: 3
  69. toc_float: true
  70. ---
  71.  
  72. ```{r setup, include=FALSE}
  73. knitr::opts_chunk$set(echo = TRUE)
  74. ```
  75.  
  76. ## R Markdown
  77.  
  78. 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>.
  79.  
  80. 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:
  81.  
  82. ```{r cars}
  83. summary(cars)
  84. ```
  85.  
  86. ## Including Plots
  87.  
  88. You can also embed plots, for example:
  89.  
  90. ```{r pressure, echo=FALSE}
  91. plot(pressure)
  92. ```
  93.  
  94. Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement