首页 > 解决方案 > 手机上 ggplot2 的闪亮下载按钮

问题描述

我在移动设备 (iOS) 上使用 downloadButton 时遇到问题,但在桌面设备上没有问题。这是服务器代码:

output$npsDown <- downloadHandler(
filename =  function() {
paste("BL", npsPlayerID(), "S", sep="")
},
content = function(file) {

#PLOT STUFF HERE

ggsave(file, plot = plot, device = "jpeg")

dev.off()

 } 
)

这是用户界面代码:

downloadButton(outputId = "npsDown", label = "Download Chart")

当我单击桌面上的下载按钮时,情节下载完美。但是当我尝试在移动设备(iOS)上执行此操作时,会发生这种情况:来自下载的奇怪代码

标签: rggplot2shiny

解决方案


您应该将添加添加contentType = 'image/png'到您的downloadHandler.

output$npsDown <- downloadHandler(
filename =  function() {
paste("BL", npsPlayerID(), "S", sep="")
},
content = function(file) {

#PLOT STUFF HERE

ggsave(file, plot = plot, device = "jpeg")

dev.off()

 },
  contentType = 'image/png'
)

推荐阅读