2017-11-20 3 views
1

사용자로부터 PDF 파일을 읽고 표시하기위한 R의 간단한 반짝이는 앱이 있습니다. 나는 그것이 작동하도록 할 수 없습니다. www 디렉토리에 반짝 서버에서 난 그냥 첫 번째 문자업로드 및 R 반짝이의 PDF보기

library(shiny) 

ui <- shinyUI(fluidPage(

    titlePanel("Testing File upload"), 

    sidebarLayout(
    sidebarPanel(
     fileInput('file_input', 'upload file (. pdf format only)', accept = c('.pdf')) 
    ), 

    mainPanel(
     uiOutput("pdfview") 
    ) 
) 
)) 

server <- shinyServer(function(input, output) { 

    observe({ 
    req(input$file_input) 
    test_file <- readBin(input$file_input$datapath, what="character") 
    writeBin(test_file, "www/myreport.pdf") 
    }) 


    output$pdfview <- renderUI({ 
    tags$iframe(style="height:600px; width:100%", src="myreport.pdf") 
    }) 

}) 

shinyApp(ui = ui, server = server) 

답변

0

나는 문제가 바이너리 읽기와 쓰기와 생각을 가지고 이름 "myreport.pdf"와 1킬로바이트 파일을 참조하십시오. 대신 file.copy을 사용하여 파일을 복사하려고하면 작동하는 것 같습니다. 또한 iframe 안에 observeEvent을 가져와 같은 세션에서 pdf가 업로드 될 때마다 iframe이 업데이트되도록했습니다.

업데이트 코드 :

library(shiny) 

ui <- shinyUI(fluidPage(

    titlePanel("Testing File upload"), 

    sidebarLayout(
    sidebarPanel(
     fileInput('file_input', 'upload file (. pdf format only)', accept = c('.pdf')) 
    ), 

    mainPanel(
     uiOutput("pdfview") 
    ) 
) 
)) 

server <- shinyServer(function(input, output) { 

    observe({ 
    req(input$file_input) 

    #test_file <- readBin(input$file_input$datapath, what="raw") 

    #writeBin(test_file, "myreport.pdf") 

    #cat(input$file_input$datapath) 

    file.copy(input$file_input$datapath,"www", overwrite = T) 



    output$pdfview <- renderUI({ 
    tags$iframe(style="height:600px; width:100%", src="0.pdf") 
    }) 

    }) 

}) 

shinyApp(ui = ui, server = server) 
+0

신난다! 감사. 이것은 효과가 있었다. –

+0

@VishalVerma이 작업이 완료되면 upvote 및 답변 표시 허용하십시오! 고마워 – amrrs