File: module_exportTab.R

package info (click to toggle)
r-cran-rlumshiny 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,304 kB
  • sloc: javascript: 922; makefile: 2
file content (100 lines) | stat: -rw-r--r-- 3,622 bytes parent folder | download | duplicates (3)
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
100
exportCodeHandler <- function(input, output, session, code) {
  
  output$exportScript <- downloadHandler(
    filename = function() { paste(input$filename, ".", "R", sep="") },
    content = function(file) {
      write(code, file)
    },#EO content =,
    contentType = "text"
  )#EndOf::dowmloadHandler()
  
}

exportPlotHandler <- function(input, output, session, fun, args) {
  
  output$exportFile <- downloadHandler(
    filename = function() { paste(input$filename, ".", input$fileformat, sep="") },
    content = function(file) {
      
      # determine desired fileformat and set arguments
      if(input$fileformat == "pdf") {
        pdf(file, 
            width = input$imgwidth, 
            height = input$imgheight, 
            paper = "special",
            useDingbats = FALSE, 
            family = input$fontfamily)
      }
      if(input$fileformat == "svg") {
        svg(file, 
            width = input$imgwidth, 
            height = input$imgheight, 
            family = input$fontfamily)
      }
      if(input$fileformat == "eps") {
        postscript(file, 
                   width = input$imgwidth, 
                   height = input$imgheight, 
                   paper = "special", 
                   family = input$fontfamily)
      }
      
      # plot  
      do.call(fun, args)
      
      dev.off()
    },#EO content =,
    contentType = "image"
  )#EndOf::dowmloadHandler()
}


exportTab <- function(id, filename) {
  
  # Create a namespace function using the provided id
  ns <- NS(id)
  
  tabPanel("Export",
           radioButtons(inputId = ns("fileformat"), 
                        label = "Fileformat", 
                        selected = "pdf",
                        choices = c("PDF   (Portable Document Format)" = "pdf",
                                    "SVG   (Scalable Vector Graphics)" = "svg",
                                    "EPS   (Encapsulated Postscript)" = "eps")),
           textInput(inputId = ns("filename"), 
                     label = "Filename", 
                     value = filename),
           fluidRow(
             column(width = 6,
                    numericInput(inputId = ns("imgheight"),
                                 label =  "Image height", 
                                 value = 7)
             ),
             column(width = 6,
                    numericInput(inputId = ns("imgwidth"),
                                 label = "Image width", 
                                 value = 7)
             )
           ),
           selectInput(inputId = ns("fontfamily"), 
                       label = "Font", 
                       selected = "Helvetica",
                       choices = c("Helvetica" = "Helvetica",
                                   "Helvetica Narrow" = "Helvetica Narrow",
                                   "Times" = "Times",
                                   "Courier" = "Courier",
                                   "Bookman" = "Bookman",
                                   "Palatino" = "Palatino")),
           tags$hr(),
           downloadButton(outputId = ns("exportFile"), 
                          label = "Download plot"),
           
           tags$hr(),
           helpText("Additionally, you can download a corresponding .R file that contains",
                    "a fully functional script to reproduce the plot in your R environment!"),
           
           downloadButton(outputId = ns("exportScript"), 
                          label = "Download R script")
           
  )
}