Adding an Email Button to Shiny Using TableTools or Otherwise

The code below creates the DataTable output, which I would like to send via email using the email button, similar to the Export button created below. Is there an easy way to add a button so that when you click on it, Microsoft Outlook appears to send data as an attachment, for example, in csv format?

Alternatively, click here and here to help with similar questions.

#Load required packages require(shiny) #Create a dataframe df <- data.frame(random=1:160) server <- function(input,output,session){ #Display df using DataTable and apply desired options output$display <- renderDataTable({df}, option=list(pageLength=100, "dom" = 'T<"clear">lfrtip', "tableTools" = list( "sSwfPath" = "//cdn.datatables.net/tabletools/2.2.3/swf/copy_csv_xls_pdf.swf", "aButtons" = list(list("sExtends" = "csv","oSelectorOpts"=list("page"="all"),"sButtonText" = "Export","aButtons" ="csv"))) ) ) } ui <- shinyUI(fluidPage( #Add a title h1('Testing TableTools'), #Add required JS libraries tagList( singleton(tags$head(tags$script(src='//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js',type='text/javascript'))), singleton(tags$head(tags$script(src='//cdn.datatables.net/tabletools/2.2.3/js/dataTables.tableTools.min.js',type='text/javascript'))), singleton(tags$head(tags$link(href='//cdn.datatables.net/tabletools/2.2.3/css/dataTables.tableTools.css',rel='stylesheet',type='text/css'))) ), mainPanel( #Display results dataTableOutput('display') ) )) shinyApp(ui = ui, server = server) 
+2
r shiny datatable tabletools
source share
1 answer

A quick way is to use mailto (which works well with Outlook).

mailto must be inside the HTML() tag for brilliant display.

 HTML( <a href="mailto:hello@rshiny.com? body='Hello,World! Check out my data.' &subject='Data' &attachment='\\myfolder\shinyData.csv'">click here for email!</a> ) 

There are two hypothetical ways to do this.

  • Enter mailto in ui.R

The code should load the datatable at the end of the user (possibly in the temp folder) and attach it there.

  1. Enter mailto in server.R

You will need a csv file already saved on your server in order to download it as an attachment. You will need to use the above code inside renderUI() , and also transfer the file from your server to the end of the user.

There is a downloadHandler() function that allows users to boot from a server, which may be useful for the above.

I never tried to transfer attachments when you try, however the above logic should allow you to create an email and get the correct path for attaching files.

+3
source share

All Articles