I'm dealing with a problem to download user requested data. I think I don't get to understand (I'm new in R and Shiny) the downloadHandler behavior. I have no problem to plot the selected file (already stored in R as a raster file BFT_PR
, YFT_PR
, and FAI
), but when trying to download it I always get the same downloadData.txt
and Error: server problem. I`ll really appreciate any help with this.
server <- function(input, output) {
output$range <- renderText({paste("Forecast from", timestart, "to", timeend)})
# Reactive value for selected dataset ----
output$model <- renderPlot({
mapInput <- reactive({
switch(input$model,
"Bluefin tuna" = BFT_PR,
"Yellowfin tuna" = YFT_PR,
"Fishing Aptitude Index"=FAI)})
palette <-colorRampPalette(c("blue", "#007FFF", "cyan",
"#7FFF7F", "yellow", "#FF7F00", "red" ))(100)
spplot(mapInput(), col.regions=palette, sp.layout= list(landmask_m, landmask_u, FZ),scales=list(draw = TRUE))
})
# Download map as geotiff ----
output$downloadData <- downloadHandler(
filename = function() {paste0(input$model, ".tif")},
content = function(file) {writeRaster(mapInput(), file)}
)
}