How can I work around the write permissions that prevent the creation of a downloadable png of html widget in a shiny app.

I created a reprex below that should download a png of an html widget using 'webshot', but I get the following error "cannot create dir plotly...._files', reason 'Permission denied'".

It works locally just fine, but not on shiny-server.
I do not want to give the shiny-server write permissions since this is not recommended for security issues. Is there another way around this issue using temporary directories?

Details:
I am using the deprecated plotly export which is a wrapper around 'webshot'. This creates an html of the html widget and then takes a virtual snapshot for the png. When it makes the html it creates the temporary plotly directory, but does not have permission and fails.

I'd like to create a temporary directory and move there then create the png and send that file along.

library(shiny)
ui <- fluidPage(
    downloadLink("downloadData", "Download2")
)

server <- function(input, output) {
    # Our dataset
    data <- mtcars
    
    output$downloadData <- downloadHandler(
        filename = function() {
            paste("data-", Sys.Date(), ".png", sep="")
        },
        content = function(file) {
            g <- 
                DiagrammeR::DiagrammeR("
  graph LR
    A-->B
    A-->C
    C-->E
    B-->D
    C-->D
    D-->F
    E-->F
")
            
            ### Create Temp Directory to run export of html widget
            ### The process involves "webshot" which will create a temp html
            ### Then take a virtual snapshot of the image
            ### The problem sometimes occurs that we don't have permission
            ### to write to the directory. 

            plotly::export(g, file = file)

            
            
        }
    )
}

shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.