2017-12-26 35 views
0

저는 랩톱의 RStudio와 우분투의 반짝이는 서버 사이에서 권한있는 문제를 겪고 있다고 생각합니다.반짝이는 서버에서 Shiny를 통해 xlsx 문서에 이미지 넣기

이 샘플 응용 프로그램은 이미지를 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() 
)) 
) 
+1

오류 메시지가 나타 납니까? tempdir()을 사용하여 임시 이미지를 저장할 장소를 확보 할 수 있습니다. 덕분에 –

+0

. tempdir은이 문제를 어떻게 해결 했는가? – cylondude

답변

0

랄프-stubner에서 힌트를 복용 전

,691,363에

png("plot.png", width=1024, height=768, units="px", res=144) 

변경 (210)

png(paste0(tempdir(), "/", "plot.png"), width=1024, height=768, units="px", res=144) 

insertImage(wb, worksheet_name, "plot.png", width=11.18, height=7.82, units="in") 

insertImage(wb, worksheet_name, paste0(tempdir(), "/", "plot.png"), width=11.18, height=7.82, units="in") 

지금 이미지는 단지 내 지역 개발의 노트북에 근무하는 대신 응용 프로그램 디렉토리의 올바른 권한과 임시 디렉토리에 기록됩니다 .