2017-12-26 7 views
0

私はラップトップでRStudioを実行している作業中の光沢のあるアプリケーションとubuntuの光沢のあるサーバーとの間で許可の問題に遭遇していると思います。イメージをshiny-server上の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からヒントを取って、私は

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") 

となりました画像は、唯一の私のローカル開発のラップトップ上で働いていた代わりに、appディレクトリの右権限を持つ一時ディレクトリに書き込まれます。

関連する問題