Save raster files using shinySaveButton

I would like to read and process a raster file, and after that, I would like to save the result using shinySaveButton the read and process steps are functioning well, but still, I can not save the output of the process!

library(shiny)
library(raster)
library(rgdal)
library(shinyFiles)

file1<- "D:\\dgm_test.tif"

ui <- fluidPage(
titlePanel(p("Dyke extraction tool", style = "color:#3474A7")),
sidebarLayout(
  sidebarPanel(
    fileInput(inputId = "dgm", accept = "tif",
              label = "Choose a raster"),
    
    
    actionButton(inputId = "click",
                 label = "Update"),
    shinySaveButton("save", "Save file", "Save file as ...", filetype= ".tif")
    # the desired format that I want at the end is .tif
    
  ),
  mainPanel(
    plotOutput("plot1"),
    plotOutput("plot2")
   )
  )
 )
server <- function(input, output,session) {
data1<- reactive({
  req(input$dgm)
  raster::raster(input$dgm$datapath)
  })
observeEvent(input$click, {

  output$plot1<- renderPlot(
    {plot(data1())
    }
  )
  output$plot2<- renderPlot(
    {plot(aggregate(data1(), fact=100, fun=mean, expand=TRUE))
# I want to enable the user to save this output as a raster(tif format) ?? 
    }
  )
 }
)
}

shinyApp(ui = ui, server = server)

could you please assist me to figure out how I can do that?

This topic was automatically closed 54 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.