2017-02-16 6 views
0

Shiny Dashboard를 개발했습니다. 반응성 파일 판독기 등을 통해 가져온 여러 데이터 프레임이 있습니다. 또한 downloadButton을 사용하여 "Generate PDF"버튼을 추가했습니다.) 내 코드에 .R 코드. 내 server.R 코드는 downloadHandler()를 구현하여 해당 요청을 처리합니다.Shiny DownloadButton() 및 downloadHandler() 500 오류

내 Windows 바탕 화면에서이 모든 작업이 완벽하게 작동합니다. 이 설정을 Linux 서버에서 실행하고 싶습니다. 물론 몇 가지 경로를 수정해야했고 Shiny Server는이 상자에서 루트로 실행됩니다. Linux 서버에서 실행되는 사이트에서 "Generate PDF"버튼을 클릭하면 거의 즉시 HTTP 500 오류가 발생합니다. 필자는 Linux 서버에서 수동으로 pdfReport.Rmd 파일을 컴파일했으며 제대로 실행됩니다. 나는 두 가지 중 하나를 추측하고

: 그것은 Windows 바탕 화면처럼

  1. 은 어떻게 든 데이터가 리눅스 박스에 같은 방식으로 전달 받고 있지 않습니다. 아마 그렇지는 않지만 가능성이 있습니다.
  2. 임시 파일에 PDF 생성이 시작될 때 시스템에 기능이 없거나 파일을 쓸 경로가 존재하지 않아 내 경로에 문제가 있습니다. 아마도 내 downloadHandler() 코드가 어떤 식 으로든 형식이 잘못되었습니다. 나는 이것이 # 1보다 더 높은 가능성이라고 생각한다. 여기

은 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/해당 변경하려하지만, 작동하지 않았다 어느 한 쪽.

http://my.url.com:3838/itpod/session/d661a858f5679aba26692bc9b4442872/download/pdfReport?w= 

나는이 문제가 있는지 궁금해하기 시작하고 난 것을 해요 : 주위를 파고, 나는 내가 "PDF를 생성"버튼 위에, 나는 "세션"과 긴 URL을 얻을 때 발견 현재 세션이나 다른 무언가의 경로에 쓰지 않습니까? 이것은 샤이니에게 새로운 영역입니다. 내가 말했듯이, 내 바탕 화면에서 잘 작동하지만 일단 Linux 서버에 배포하면 제대로 작동하지 않습니다. 어떤 도움이라도 대단히 감사 할 것입니다. 미리 감사드립니다!

답변

0

Ok - 많은 문제를 해결 한 후 주 pdfReport.Rmd 파일에 대한 종속성이있는 반짝이는 webroot에있는 파일 중 일부가 코드가 임시 디렉토리에 보고서를 복사했기 때문에 표시되지 않았다는 것을 알았습니다 .

내 웹 루트에서 임시로 파일을 모두 복사하고 싶지 않았기 때문에 웹 루트 자체에서 보고서를 렌더링하기로 결정했습니다. 나를 위해, 내 애플 리케이션이 어쨌든 루트로 실행되고 있기 때문에 이것은 큰 문제가되지 않습니다.

지금 나는 그것이 작동 가지고이 문제를 해결합니다

는 기본적으로 내 수정 사항은 다음을 수행하는 것입니다 :

  1. 는 일반 사용자
  2. 보다는 파일의 사본으로 서비스를 실행합니다 그 보고서가 의존하는 경우 보고서 코드에서 정적으로 참조해야합니다.

나는 이것을 읽고 그것에 대해 노력하고있는 모든 사람들을 사과드립니다. 내 수정 위의 다음이었다 코드로했다 :

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

     report <- file.path(getwd(), "pdfReport.Rmd") 
     #tempReport <- file.path(tempdir(), "pdfReport.Rmd") 
     #file.copy("pdfReport.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(report, output_file = file, params = params, envir = new.env(parent = globalenv()) 
     ) 
     } 
    ) 

    }) 

공지 사항, 그 대신 임시 디렉토리에 파일을 복사, 난 그냥 현재 작업 디렉토리에있는 파일을 지정합니다.