Downloading an object created in a shiny app as an rda file

697 views
Skip to first unread message

Fred Lubbe

unread,
Sep 18, 2015, 5:03:48 PM9/18/15
to Shiny - Web Framework for R
I am trying to write an app that allows a user to create a design object and then download that object as an rda file to be used later. The object is being created and the file is being downloaded, but the data is not being properly written to the file. The code below shows how the design object is created and my attempt at downloading it.

 pbDesign<-reactive({
            pb(nruns= input$runs ,n12.taguchi= FALSE ,nfactors= input$fac, ncenter= input$nc ,
         replications= input$nr ,repeat.only= FALSE ,randomize= rand ,seed= 13851,
         factor.names=names)      
    })

 dz <- reactiveValues()
    observe({
      if(input$act==0)
        return()
      else
      if(!is.null(pbDesign()))
      isolate(
          dz <- pbDesign()
       )
    })


    output$downloadRDA <- downloadHandler(
      filename <- function(){       
        paste(input$desName,'.rda')
      },
     
      content = function(file) {
        save(dz, file = file)
      }
    )

 I have tried using the export.design() function in place of save but that does not seem to work either.
this is what gets assigned to dz:

$impl
<ReactiveValues>
  Public:
    .allValuesDeps: environment
    .dependents: environment
    .label: reactiveValues4787
    .namesDeps: environment
    .setLabel: function
    .values: environment
    .valuesDeps: environment
    clone: function
    get: function
    initialize: function
    mset: function
    names: function
    self: environment
    set: function
    toList: function


attr(,"class")
[1] "reactivevalues"
attr(,"readonly")
[1] FALSE

I am not sure if it is due to me not properly understanding the downloadHandler function or if it has something to do with my use of the save() function. Is there any function similar to write.csv() but for an rda file?

Any help or advice on this topic would be greatly appreciated.


Abhinav Agrawal

unread,
Sep 20, 2015, 3:23:02 AM9/20/15
to Shiny - Web Framework for R
Dear Fred,
You might want to try to use saveRDS(object, file). Not sure if you already tried that to download in .Rdata format.
Also, later, you can use the readRDS to load the .Rdata file.

Here is an example in case it helps. 


Regards,
Abhinav
Reply all
Reply to author
Forward
0 new messages