displaying a pdf from a local drive in shiny

后端 未结 3 1619
猫巷女王i
猫巷女王i 2020-11-28 10:54

I\'m still new to r and shiny, and i\'m stumped with what should otherwise be simple logic. I am trying to display pdf files in imageOutput widgets but with no luck. Could s

3条回答
  •  暖寄归人
    2020-11-28 11:13

    Create a folder called www in the original directory that contains your server.R and ui.R scripts. Place the PDF in the www/ folder, then use something like the code below:

    In server.R:

    shinyServer(function(input, output) {
    
      observeEvent(input$generate, {
        output$pdfview <- renderUI({
          tags$iframe(style="height:600px; width:100%", src="foo.pdf")
        })
      })
    })
    

    In ui.R:

    shinyUI(fluidPage(
    
      titlePanel("Display a PDF"),
    
      sidebarLayout(
        sidebarPanel(
          actionButton("generate", "Generate PDF")
        ),
    
        mainPanel(
          uiOutput("pdfview")
        )
      )
    ))
    

提交回复
热议问题