How to save (not upload) a file created using the Shiny interface?

I asked this question in the Shiny Google group, but after its publication, it is deleted immediately, I do not know why.

So, I ask this question here.

I know how to download a file created from a Shiny application, but I unsuccessfully spent a couple of hours finding how to save the file to my hard drive. Please, could you show me a way to do this? For example, I would like to save a file created using sink () or an RData file.

The following is an (artificial) example of one of my many attempts. The sweaveSave () function does not work. Please do not pay attention to the plot, this does not play a role in my question.

server.R

library(shiny) ## ## function creating a Sweave report ## createReport <- function(file){ sink(file) cat( "\\documentclass{article}\n \\begin{document}\n \\SweaveOpts{concordance=TRUE} This is the Rnw file.\n <<fig=TRUE>>= plot(0,0) @\n \\end{document}\n") sink() } ## ## Shiny server ## shinyServer(function(input, output) { ## ## Create plot ## createPlot <- reactive({ # generate an rnorm distribution and plot it titl <- paste0("Exponential distribution with rate ", round(input$parameter,2)) curve(dexp(x,rate=input$parameter), from=0, to=5, main=titl, ylab=NA, xlab=NA) }) ## ## output : plot ## output$distPlot <- renderPlot({ createPlot() }) ## ## output : download Sweave file ## output$sweavedownload <- downloadHandler( filename="report00.Rnw", content = createReport ) ## ## save Sweave file ## sweaveSave <- reactive({ if(input$save){ createReport("REPORT00.Rnw") }else{NULL} }) }) 

ui.R

 library(shiny) shinyUI(pageWithSidebar( # Application title headerPanel("Hello Shiny!"), # Sidebar panel sidebarPanel( sliderInput("parameter", "Rate parameter:", min = 0.0000000001, max = 10, value = 5), checkboxInput("save", "Check to save and download") ), # Main panel mainPanel( plotOutput("distPlot"), conditionalPanel( condition = "input.save", downloadLink("sweavedownload", "Download") ) ) )) 
+4
source share
1 answer

This will make your life easier with the shinyFiles package.

 install.package('shinyFiles') require(shinyFiles) shinyFilesExample() 
+1
source

All Articles