Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to perform an operation not allowed by the security policy `PDF' #384

Closed
dcaud opened this issue Oct 26, 2023 · 5 comments
Closed

Comments

@dcaud
Copy link

dcaud commented Oct 26, 2023

The error happens when trying to write to a pdf with image_write() on shinyapps.io. I think the Posit needs to change the policy.xml file on their newly updated Ubuntu servers (see https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion).

Do you have ideas to fix this issue without needing to wait for Posit to make a change?

Here's an example app that reproduces the error:

library(shiny)
library(magick)

ui <- fluidPage(
  titlePanel("Error when downloading as PDF"),
  
  sidebarLayout(
    sidebarPanel(
      radioButtons("fileType", "Choose File Type:",
                   choices = c("PDF", "JPEG"),
                   selected = "PDF"),
      downloadButton("downloadFile", "Download")
    ),
    
    mainPanel(
      imageOutput("displayImage")
    )
  )
)

server <- function(input, output, session) {
  
  img <- image_read("wizard:")
  
  output$displayImage <- renderImage({
    tmp <- tempfile(fileext = ".png")
    image_write(img, path = tmp, format = "png")
    list(src = tmp)
  }, deleteFile = TRUE)
  
  output$downloadFile <- downloadHandler(
    filename = function() {
      if (input$fileType == "PDF") {
        paste0("converted_", Sys.Date(), ".pdf")
      } else {
        paste0("converted_", Sys.Date(), ".jpeg")
      }
    },
    content = function(file) {
      if (input$fileType == "PDF") {
        # The write function w/ PDF seems to be at odds with a policy that can be revised.
        image_write(img, path = file, format = "pdf")
      } else {
        image_write(img, path = file, format = "jpeg")
      }
    }
  )
}

shinyApp(ui = ui, server = server)

Related: rstudio/shinyapps-package-dependencies#289 (comment)

@jeroen
Copy link
Member

jeroen commented Oct 26, 2023

Yeah I don't think it is possible to work around the policy restrictions. I can try to ping the sysadmins...

@jeroen
Copy link
Member

jeroen commented Oct 26, 2023

I actually thought they had just removed the policy: rstudio/shinyapps-package-dependencies#323

@dcaud
Copy link
Author

dcaud commented Oct 26, 2023

They definitely removed the policy a while back, but it has reappeared.

@dcaud
Copy link
Author

dcaud commented Oct 27, 2023

Thanks, jeroen! I think what happened is that they wrote a script to remove policy.xml for Focal that has was included (and updated) to work with Jammy.

@dcaud
Copy link
Author

dcaud commented Dec 31, 2023

The Posit folks fixed this so new apps launched there do not continue to have this problem.

@dcaud dcaud closed this as completed Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants