Skip to content

Instantly share code, notes, and snippets.

@amrrs
Created November 21, 2017 08:04
Show Gist options
  • Save amrrs/184006b54a0cbe6baa62595cf7c4fdb4 to your computer and use it in GitHub Desktop.
Save amrrs/184006b54a0cbe6baa62595cf7c4fdb4 to your computer and use it in GitHub Desktop.
How to upload and embed pdf in R shiny (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)
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment