I'd like for end-users to be able to export a .png of a visNetwork graphic built and deployed with Shiny. I'm able to do that by using a visExport
line at the end of my renderVisNetwork
code, but I don't like the look of the button that gets generated in the output, the button itself gets included on the exported .png, and the quality of the .png itself isn't all that great. I like the look of the button generated by downloadButton
in the UI, but I'm doing something wrong with downloadHandler
on the server end. While running in the browser, I click the download button, get the download dialog, and am able to save the file, but the file is blank (file size of 318 bytes). Trying as .pdf doesn't work either. Here's my code:
ui.R:
downloadButton('ConDL', label='Download png')
server.R:
# Create network
ConNet <- function(){
visNetwork(Nodes(), Edges()) %>%
#all the other stuff to create the network which works fine
}
# Draw visualization - works fine
output$ConNet <- renderVisNetwork({
ConNet()
})
# Download png of visualization - no errors displayed in browser or
# console when testing, but exports blank png
output$ConDL <- downloadHandler(
filename="Con.png",
content= function(file) {
png(file)
ConNet()
dev.off()
}
)
I've followed the advice given here about generating the object with a function instead of a reactive: Downloading png from Shiny (R). Turning the preceding reactives that feed into ConNet to functions was also ineffective. I am having the app open in a browser (Firefox) rather than running through the preview pane. Trying print(ConNet())
in the content section doesn't help, either, so I'm not sure what I'm missing.
Bonus if I can get the .png to exclude the navigation buttons produced with visInteraction
when I create the network - they're useful for the interactive part, but clutter a static graphic.