I'm trying to download a BSON file that I export to my shiny app from a MongoDB using the mongolite package. This is the code in my download button:
output$downloadTiming <- downloadHandler(
filename = "/keyTiming.bson",
content = function(fileToDownload){
mongolite::mongo(
collection = "keyTiming",
url = "mongodb://<User>:<Pass>@<url>"
)$export(fileToDownload, bson = TRUE)
}
)
When I try to download it, it says "Error: inherits(con, "connection") is not TRUE". I have spent a good amount of time researching and have found nothing, and hope that someone here can be of use.
I figured it out eventually. The final code looks like this
output$downloadTiming <- downloadHandler(
filename <- function(){
return("timingOut.bson")
},
content <- function(file){
outFile = file("timingOut.bson")
mongolite::mongo(
collection = "timings",
url = "mongodb://<user>:<pass>@<database>"
)$export(outFile, bson = TRUE)
file.copy("timingOut.bson", file, overwrite = TRUE)
}
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.