我開發了一個Shiny Dashboard,我有幾個數據框可以通過被動文件讀取器導入等。我還添加了一個「Generate PDF」按鈕,使用downloadButton )在我的ui.R代碼中。我的server.R代碼實現了downloadHandler()來處理這個請求。Shiny downloadButton()和downloadHandler()500錯誤
在我的Windows桌面上,這一切都很完美。我希望它能在我設置的Linux服務器上運行。當然,我必須修改一些路徑,並且Shiny Server在這個盒子上以root身份運行。當我在Linux服務器上運行的網站上單擊「生成PDF」按鈕時,我幾乎立即就會收到HTTP 500錯誤。我自己手動編譯了Linux服務器上的pdfReport.Rmd文件,它運行得很好。
我猜測兩件事情之一:
- 不知何故數據沒有獲得通過在Linux中相同的方式,它在Windows桌面上。這可能不太可能,但這是一種可能性。
- 我的路徑有問題,所以當臨時文件被寫入開始生成PDF時,系統沒有能力或路徑不存在寫入文件。可能我的downloadHandler()代碼在某種程度上是格式錯誤的。我認爲這比第一名更有可能。
這裏是我的downloadHandler(代碼):
output$pdfReport <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = reactive({paste0("/srv/shiny-server/itpod/","ITPOD-",Sys.Date(),".pdf")}),
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path("/srv/shiny-server/itpod", "pdfReport.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
params <- list(ilp=updateILP(), ico=updateICO(), sec=updateSecurity(), ppwc=updateWorkPreviousPeriodCompleted(),
pow=updateOngoingWorkCABApproved(), pwcr=updatePlannedWorkCABRequested(), epca=updateEmergencyChangesPendingCABApproval(),
fac=updateFacilities(), drs=updateDRStatus(), ov=updateOperationalEvents(), sl=updateStaffLocations(),
w = updateWeather())
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, output_file = file, params = params, envir = new.env(parent = globalenv())
)
}
)
我想,也許這條道路只是沒有寫的,所以我試圖改變到/ tmp,但是沒有奏效無論是。閒逛,我發現,當我在「生成PDF」按鈕,我得到一個長的URL與「會話」:
http://my.url.com:3838/itpod/session/d661a858f5679aba26692bc9b4442872/download/pdfReport?w=
我開始懷疑這是問題,我是不寫入當前會話的路徑或什麼?這對Shiny來說是一個新的領域。就像我說的,在我的桌面上它工作正常,但是一旦我將它部署到Linux服務器,它就不能正常工作。任何幫助將非常感激。提前致謝!