ramnathv/rCharts

rCharts2 and download file

Closed this issue · 2 comments

Hi,
my app works fine, I can show an interactive plot in external or window mode but when i try to download it, empty file is generated. Without rCharts and normal output-plot (no interactivity) download works fine.

Here the code:
ui.R

`# DOWNLOAD
                          tabPanel(title = p(icon("fa fa-download"), "Download Plot"),

                                   # select plot's FORMAT output
                                   selectInput(
                                       inputId = "downloadPlotType",
                                       label   = h5("Select download file type"),
                                       choices = list("PDF"  = "pdf","BMP"  = "bmp","JPEG" = "jpeg","PNG"  = "png")),
                                   # enter FILENAME
                                   textInput(
                                       inputId = "downloadPlotFileName",
                                       label = h5("Enter file name for download")),

                                   # DOWNLOAD BUTTON
                                   downloadButton("downloadData", "Download")
                                   )`

server.R

`## plotInput()
      plotInput <- function(){
          p <- nPlot(~ Test.Cycle, group = "esito", data = dataSubset(), type = "multiBarChart")
#           p <- ggplot(dataSubset(), aes(x=ciclo, fill=esito))
#           p <- p + geom_bar(width = 0.5) + xlab("cycle") + ylab("Substitutions") + labs(fill="") + ggtitle("test result")
#           p <- p + scale_fill_manual(values=c("failure" = "red", "success" = "green"))
          p$xAxis(axisLabel = "cycle")
          p$yAxis(axisLabel = "Frequency")
          print(p)
      }

      ## Render the plot - histogram
       output$plot <- renderChart2({
           (plotInput())
      })

       ## Get the download file name
       downloadPlotFileName <- reactive({
           input$downloadPlotFileName
       })

       ## Get the download file type
       downloadPlotType <- reactive({
           input$downloadPlotType  
       })

       ## Download the plot
       output$downloadData <- downloadHandler(
           # creating filename output with extension
           filename = function() {
               paste(downloadPlotFileName(), downloadPlotType(), sep=".")   
           },
           content = function(file) {
               plotFunction <- match.fun(downloadPlotType())
               plotFunction(file)
               #png(file)
               print(plotInput)
               dev.off(which=dev.cur())
           }
       )`
`R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252    LC_MONETARY=Italian_Italy.1252
[4] LC_NUMERIC=C                   LC_TIME=Italian_Italy.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] markdown_0.7.7 dplyr_0.4.3    ggplot2_1.0.1  xlsx_0.5.7     xlsxjars_0.6.1 rJava_0.9-7   
[7] rCharts_0.4.5  shiny_0.12.2  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.3      rstudioapi_0.3.1 whisker_0.3-2    magrittr_1.5     MASS_7.3-43     
 [6] munsell_0.4.2    colorspace_1.2-6 xtable_1.7-4     lattice_0.20-33  R6_2.1.1        
[11] stringr_1.0.0    plyr_1.8.3       tools_3.2.2      parallel_3.2.2   grid_3.2.2      
[16] gtable_0.1.2     DBI_0.3.1        htmltools_0.2.6  lazyeval_0.1.10  assertthat_0.1  
[21] yaml_2.1.13      digest_0.6.8     RJSONIO_1.3-0    reshape2_1.4.1   mime_0.4        
[26] stringi_0.5-5    scales_0.3.0     jsonlite_0.9.17  httpuv_1.3.3     proto_0.3-10 `

Any help?

There is no way to download interactive plots generated by rCharts inside of a shiny application.

ah ok, is it at least possibile to dowload the static output of the last interactive session of the app?
I mean as a normal plot without interactivity.

Anyway, rCharts is awesome package, thank you