title: "Download" button doesn't work in my shiny app
body: <p>I am almost done with my shinyapp, the last part is to add a download button in my server.R. I followed the instructions of "how to download" in Rshiny but it didn't really work in my case. </p>
  
  <p>Here is my ui.R</p>
  
  <pre><code>library(shiny)
  library(hurricaneexposure)
  library(hurricaneexposuredata)
  library(ggplot2)
  
  
  data("hurr_tracks")
  
  storms &lt;- unique(hurr_tracks$storm_id)
  storm_years &lt;- as.numeric(gsub(".+-", "", storms))
  storms &lt;- storms[storm_years &lt;= 2011]
  
  years &lt;- unique(storm_years)
  years &lt;- years[years &lt;= 2011]
  
  
  shinyUI(fluidPage(
  
    # Application title
    titlePanel("County-level exposure to tropical storms"),
  
    sidebarLayout(
      sidebarPanel(
        selectInput("year", label = "Storm year", years,
                selected = "1988"),
  
    # This outputs the dynamic UI component
    uiOutput("ui"),
    selectInput("metric", label="Storm exposure metric:",
                choices =  c("distance", "rainfall", "wind"),
                selected = "distance"),
    numericInput("limit", 
                 label = "Limit range", 
                 value = 100),
    downloadButton('downloadData', 'Download The Table')
  
  ),
  mainPanel(plotOutput("map"))
    ),
    fluidRow(
      DT::dataTableOutput("table")
    )
  
  ))
  </code></pre>
  
  <p>And here is my server.R</p>
  
  <pre><code>library(shiny)
  library(devtools)
  library(ggplot2)
  library(hurricaneexposuredata)
  library(hurricaneexposure)
  library(choroplethrMaps)
  library(dplyr)
  
  data("hurr_tracks")
  data("county_centers")
  
  storms &lt;- unique(hurr_tracks$storm_id)
  storm_years &lt;- as.numeric(gsub(".+-", "", storms))
  storms &lt;- storms[storm_years &lt;= 2011]
  
  years &lt;- unique(storm_years)
  years &lt;- years[years &lt;= 2011]
  
  
  all_fips &lt;- unique(county_centers$fips)
  
  ## Split storm_id based on same year
  stm &lt;- split(storms, gsub(".+-", "", storms))
  stm &lt;- lapply(stm, function (x) gsub("-.+", "", x))
  
  shinyServer(function(input, output, session) {
  
    output$ui &lt;- renderUI({
  
      selectInput("storm_name", label = "Storm name", stm[input$year],
                  selected = "Alberto")
  
    }) 
  
    output$map &lt;-renderPlot({
      storm_id &lt;- paste(input$storm_name, input$year, sep = "-")
      a &lt;- map_counties(storm = storm_id, metric = input$metric)
      map_tracks(storms = storm_id, plot_object = a, plot_points = FALSE) + 
        ggtitle(paste(input$storm_name, input$year, input$metric, sep = ", "))
  
    })
  
  
    output$table &lt;- DT::renderDataTable(DT::datatable({
     if(input$metric == "distance"){
       tab_out &lt;- county_distance(counties = all_fips, start_year = input$year, 
                       end_year = input$year, dist_limit = input$limit) %&gt;%
         dplyr::filter(storm_id == paste(input$storm_name,
                                         input$year, sep = "-")) %&gt;%
        dplyr::left_join(county_centers, by = "fips") %&gt;%
         dplyr::mutate(county = paste(county_name, state_name, sep =  ", ")) %&gt;%
         dplyr::select(county, fips, closest_date, storm_dist) %&gt;%
         arrange(storm_dist)
     } else if (input$metric == "rain"){
       tab_out &lt;- county_rain(counties = all_fips, start_year = input$year, 
                              end_year = input$year, rain_limit = input$limit) %&gt;%
         dplyr::filter(storm_id == paste(input$storm_name,
                                         input$year, sep = "-")) %&gt;%
         dplyr::left_join(county_centers, by = "fips") %&gt;%
         dplyr::mutate(county = paste(county_name, state_name, sep =  ", ")) %&gt;%
         dplyr::select(county, fips, closest_date, tot_precip) %&gt;%
         dplyr::rename(rainfall_mm = tot_precip) %&gt;%
         arrange(desc(rainfall_mm))
     } else if(input$metric == "wind"){
       tab_out &lt;- county_wind(counties = all_fips, start_year = input$year, 
                                  end_year = input$year, wind_limit = input$limit) %&gt;%
         dplyr::filter(storm_id == paste(input$storm_name,
                                         input$year, sep = "-")) %&gt;%
         dplyr::left_join(county_centers, by = "fips") %&gt;%
         dplyr::mutate(county = paste(county_name, state_name, sep =  ", ")) %&gt;%
         dplyr::select(county, fips, max_sust) %&gt;%
         dplyr::rename(wind_mps = max_sust) %&gt;%
         arrange(desc(wind_mps))
     }
    })
    )
    output$downloadData &lt;- downloadHandler(
      #filename = function() { paste(input$storm_name, input$year, input$metric,'.csv', sep='_') },
      filename = "ex.csv",
      content = function(file) {
        write.csv(tab_out, file)
      })   ### if I can recall the table
  
  })
  </code></pre>
  
  <p>The codes look long but I hope someone can successfully run it. The idea for this app is easy, I am just wondering how to download my output (just that table) as csv format </p>