remove data file after plotting

823 views
Skip to first unread message

anny9699

unread,
Mar 30, 2015, 4:21:09 PM3/30/15
to shiny-...@googlegroups.com
Hi,

Is there a way to remove the data file after plotting? I download the data to the machine where the shiny server is and generate some plots based on the data. After the app is exited or the plot is finished, I wish to remove the data file but don't know how to do it. Is there a way to do it? 

I tried to put the code inside function(input, output) right after renderPlot(), however it doesn't work. Does anyone have some suggestion?

Thanks a lot!
Anny

Joe Cheng

unread,
Mar 30, 2015, 6:35:50 PM3/30/15
to anny9699, shiny-...@googlegroups.com
You probably don't want to delete it right after renderPlot; the plot will need to render again if the user resizes the browser window.

Add a "session" argument to your server function, i.e. "function(input, output, session)" then call something like this:

session$onSessionEnded(function() {
  if (!is.null(input$file1)) {
    file.remove(input$file1$datapath)
  }
})

though this will only delete the most recently uploaded file in this session, if any. If you want to delete more, keep a list of them as you go, and delete them all at the end.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/485af40b-856c-45d3-8d13-eb131bcc184e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anny Chen

unread,
Mar 30, 2015, 6:53:42 PM3/30/15
to Joe Cheng, shiny-...@googlegroups.com
Thanks Joe for the explanation!

May I ask if I just want to delete them all at the end, shall I still need the "session" argument? Where shall I put the file.remove()? I tried to put it inside shinyServer() or outside shinyServer, but it seems not working.

Thanks a lot!
Anny

Anny Chen

unread,
Mar 30, 2015, 7:11:32 PM3/30/15
to Joe Cheng, shiny-...@googlegroups.com
Hi Joe,

I got it. I might still need the session elements to control.

Thanks a lot!
Anny

Renger van Nieuwkoop

unread,
Feb 17, 2017, 8:18:44 AM2/17/17
to Shiny - Web Framework for R
Hi Joe

And if I want to delete a file during my session? I tried the following

fileInput('file2', 'Choose File') in the ui

and

   observeEvent(input$file2, {
      if (!is.null(input$file2)) {
        file.remove(input$file2$datapath)
        }
    })

in the server.R file, but this doesn't work.

I also tried with a seclectInput of a list of all files, but same problem.

Cheers
Renger


Joe Cheng

unread,
Feb 17, 2017, 2:16:11 PM2/17/17
to Renger van Nieuwkoop, Shiny - Web Framework for R
What doesn't work? Can you clarify what you're trying to do and what is going wrong?

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/1af8cd2d-5690-4763-bdd7-e2182853aa54%40googlegroups.com.

Renger van Nieuwkoop

unread,
Feb 17, 2017, 3:10:22 PM2/17/17
to Shiny - Web Framework for R, rvanni...@gmail.com
In my shiny app users can upload several excel files to compare results, also results that are meant for testing. If the testing is over, these files should be deleted).

I read a list of files with

    list_of_excelfiles <- unlist(list.files(pattern = "xlsx"))


and want to have the possibility for the user to choose one of these files and delete it.

I tried with the following in the ui

      selectInput("delmodel", h4("File to delete:"),
             choices
=  c("None", unique(as.character(list_of_excelfiles))),
             selectize
= FALSE
     
)

and then use the input$delmodel to get the chosen file deleted. That is why, I was looking at this post.

Cheers and thanks for looking at my question
Renger




On Friday, February 17, 2017 at 8:16:11 PM UTC+1, Joe Cheng [RStudio] wrote:
What doesn't work? Can you clarify what you're trying to do and what is going wrong?
On Fri, Feb 17, 2017 at 5:18 AM, Renger van Nieuwkoop <rvanni...@gmail.com> wrote:
Hi Joe

And if I want to delete a file during my session? I tried the following

fileInput('file2', 'Choose File') in the ui

and

   observeEvent(input$file2, {
      if (!is.null(input$file2)) {
        file.remove(input$file2$datapath)
        }
    })

in the server.R file, but this doesn't work.

I also tried with a seclectInput of a list of all files, but same problem.

Cheers
Renger


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages