att / rcloud.shiny

Shiny support for RCloud
Other
4 stars 12 forks source link

downloadHandler loses the filename #28

Closed gordonwoodhull closed 6 years ago

gordonwoodhull commented 6 years ago

As reported on internal Stack, the following should use the supplied filename, but instead the downloaded filename is the id of the button (downloadData):

library(rcloud.shiny)
library(shiny)

ui <- fluidPage(
  downloadButton("downloadData", "Download")
)

server <- function(input, output) {
  # Our dataset
  data <- mtcars

  output$downloadData <- downloadHandler(
    filename = function() {
      paste("data-", Sys.Date(), ".csv", sep="")
    },
    content = function(file) {
      write.csv(data, file)
    }
  )
}

rcloud.shinyApp(ui=ui,server=server) 
gordonwoodhull commented 6 years ago

If the analysis from internal Stack is true, this may be an issue of proxy.R:

Somehow, the proxy layer stripped part of the response headers off rendering the donwload button incapable of setting filename and extension.

This can be observed by trying the two different URL out that are generated with the button (you can capture the URL behind the button by right-clicking on it), and debugging the headers. We use curl here.

netcat using direct request (somehow curl did not work or was hanging):

nc 130.6.32.116 4115
GET /session/48a03b0abc890dc45afabc778638c347/download/downloadData?w= HTTP/1.1

HTTP/1.1 200 OK
Content-Disposition: attachment; filename="data-2018-06-12.csv"
Cache-Control: no-cache
X-UA-Compatible: IE=edge,chrome=1
Content-Type: text/csv
Content-Length: 1783

"","mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"
"Mazda RX4",21,6,160,110,3.9,2.62,16.46,0,1,4,4

curl using shiny.html

TXMACL01JD3714:~ jd3714$ curl -I -L https://rcloud.web.att.com/proxy.R/jd3714/ba3bfe6d-0df7-45da-b445-20590f167db5:3387/session/d22ae243915324ff21095e5610bc208c/download/downloadData?w=
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Tue, 12 Jun 2018 15:37:46 GMT
Content-Type: text/csv
Content-Length: 1783
Connection: keep-alive
Cache-control: no-cache

You can see that the "Content-Disposition" header is gone, although it still has a "Content-Type: text/csv" header.

So that indicates a bug in the shiny.html layer, it unnecessarily stripped of some of the needed headers, causing the downloadButton to partially break.

gordonwoodhull commented 6 years ago

@useless5771, could you troubleshoot this a little more and figure out whether it's an rcloud.shiny issue or core RCloud issue? Thanks!