【发布时间】:2018-06-07 13:40:40
【问题描述】:
我相信我在通过笔记本电脑上的 RStudio 运行的闪亮应用程序和 ubuntu 上的闪亮服务器之间遇到了权限问题。
例如,此示例应用程序将在 xlsx 文档中写入图像并让您下载 xlsx。它将在本地运行闪亮的 rstudio 中工作,但不能通过闪亮服务器运行。我猜有一种方法可以暂时以安全的方式编写 png 并将其回调以写入带有闪亮服务器的犹太洁食的 xlsx。
server.R
library(shiny);library(openxlsx);library(ggplot2)
shinyServer(function(input, output) {
output$downloadReport <- downloadHandler(
filename = "test.xlsx",
content = function(file){
wb <- createWorkbook(paste0(Sys.time(), ".xlsx"))
my_plot <- ggplot(mtcars) + geom_line(aes(x = cyl, y = gear))
worksheet_name <- "ggplot"
addWorksheet(wb, worksheet_name)
png("plot.png", width=1024, height=768, units="px", res=144)
print(my_plot)
dev.off()
insertImage(wb, worksheet_name, "plot.png", width=11.18, height=7.82, units="in")
saveWorkbook(wb, file, overwrite = TRUE)
})
})
ui.R
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
helpText(),
downloadButton('downloadReport')),
mainPanel()
))
)
【问题讨论】:
-
您是否收到任何错误消息?您可以使用 tempdir() 来获取存储临时图像的保存位置。
-
谢谢。 tempdir 是我解决此问题的方法。
标签: r ggplot2 shiny xlsx shiny-server