running R package using shiny and saving files into computer automatically

Hi all,
I have an R package I need run using shiny. The outputs need to be saved as a result of the model run to a designated location (relative path) in the computer, rather than simply displaying on the web page.Can someone point me to an example or documentation.

thanks

Hi,

Welcome to the RStudio community!

Here is an example:

library(shiny)

ui <- fluidPage(
  
  actionButton("btn","Save locally")
  
)

server <- function(input, output, session) {
  
  observeEvent(input$btn, {
    write.csv(data.frame(x = 1:10), "myData.csv")
  })
  
}

shinyApp(ui, server)

This will write the file to the Shiny app folder. You can set a relative path from there. Beware though that if you are running this on a server, going up from the app root folder might cause issues, as Shiny is supposed to run everything within its own folder. Saving in subfolders from the main one is no issue. On a local machine, using absolute or relative paths should not cause issues.

Hope this helps,
PJ

2 Likes

Thank you very much for this!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.