我正在使用plotly包来以 Shiny 的方式显示绘图。在我的本地计算机上,绘图完美呈现,但是当我在 Shiny 的服务器上运行 Shiny 的应用程序时,我收到错误“错误:无法打开文件‘Rplots.pdf’”,其中应该渲染绘图。我尝试使用 dev.off() 命令,因为我已经阅读了一些其他可能的解决方案,这些解决方案引用了此作为可能的解决方案。下面我粘贴了用于在 server.R 脚本中创建图形的代码:
output$recSalesPlot <- renderPlotly({
BWplot_rec <- ggplot(d1, aes_string(x = "End_of_Week", y = input$metric_rec))
BWplot_rec <- BWplot_rec + geom_line(aes(color = Group), size = .25)
BWplot_rec <- BWplot_rec + geom_point(aes(color = Group), size = 2)
BWplot_rec <- BWplot_rec + xlab("Week")
if(input$metric_rec == "NetSales"){
BWplot_rec <- BWplot_rec + ylab("Euros")
}
BWplot_rec <- BWplot_rec + ggtitle(paste0("Average ", input$metric_rec, " Per Group Per Week"))
BWplot_rec <- BWplot_rec + guides(color=FALSE)
BWplot_rec <- BWplot_rec + theme(panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank())
p <- ggplotly(BWplot_rec)
p
})
}
在 ui.R 脚本中,我使用以下命令来调用绘图:
plotlyOutput("recSalesPlot", width = "100%", height = 600)
最佳答案
我不能说我理解问题的根源或为什么我的解决方案对我有效,但我遇到了同样的问题,只是在我的开头添加了 pdf(NULL)
脚本和一切似乎都工作得很好。不需要 dev.off()
(添加它会给我带来错误)。
关于shiny - Plotly 绘图未在 Shiny 的服务器上渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36777416/