Savewidget to default browser location not working directory

I've deployed my first large modular app to our company's Rconnect server. Great.

Now, rightly 20 out of the 250 users are asking me why I did not include a save functionality for the fancy DT
datatables I've built for them.

I wanted to do provide both an html file via DT::saveWidget and a PNG to allow my users to use the tables in reports etc.

So, I used an actionbutton in the module's server side:

observeEvent( input$downloadFigure, {
dat_dat <- DT::datatable(dat)
DT::saveWidget(dat_dat, 'foo.html')
}
but that just saves the widget to my own working directory which is hosted on an S3 instance etc. How can I send the file 'foo.html' to the users' browser default save location?

Separately, is it possible to also create a png file with only the widget (i.e. not the remaining webpage?)

I already use the DT buttons to download data and pdfs with no formatting or complex color-coding but I need the entire form/structure not just the values.

@john_doe congrats that you have deployed your large app on RStudio Connect!
About downloading the html file to the user's browser location: you can use a downloadhandler for this. See below for an example how you could do this.

library(shiny)
library(DT)

ui <- fluidPage(
  downloadLink("downloadData", "Download")
)

server <- function(input, output) {
  output$downloadData <- downloadHandler(
    filename = function() {
      "foo.html"
    },
    content = function(file) {
            dat_dat <- DT::datatable(mtcars,
                               options = list(
                                 initComplete = JS(
                                   "function(settings, json) {",
                                   "$(this.api().table().header()).css({'background-color': '#000', 'color': '#fff'});",
                                   "}")))
      DT::saveWidget(dat_dat, file)
    }
  )
}
shinyApp(ui, server)

Thank you for your response. I implemented your suggestion but unfortunately the html file does not retain any of the colors/format of the table - which is the only reason I needed this solution. Wouldn't converting to PNG, SVG or PDF help with the datatable retaining the colors, and other elements?

Would a png / webshot solution enable this?

I am not sure why it doesn't pick up the styling in your application. I have updated my example with a colored header, which does appear in the html file.

Maybe you can create a reproducible example?

A webshot/appshot could work but I think you can only create a PNG for the whole application and not just one component.

This topic was automatically closed 21 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.