使用TableTools或其他方式在Shiny中添加电子邮件按钮 [英] Adding an Email button in Shiny, using TableTools or otherwise

查看:176
本文介绍了使用TableTools或其他方式在Shiny中添加电子邮件按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码生成一个DataTable输出,我想通过电子邮件按钮发送电子邮件,类似于下面创建的导出按钮。是否有一个简单的方法来添加一个按钮,以便当您点击它会弹出Microsoft Outlook发送数据表作为附件,说csv格式?

The code below produces a DataTable output that I'd like to have it emailed using an Email button, similar to the Export button created below. Is there an easy way to add a button so that when you click, it pops up Microsoft Outlook to send the datatable as an attachment, say in csv format?

此外,请点击此处此处帮助一个类似的问题。

Also, please click here and here to help with a 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)


推荐答案

一个简单的方法是使用 mailto (可以与Outlook一起使用)。

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

mailto 将需要位于 HTML()标签内,以使其发光。

The mailto would need to be inside an HTML() tag for shiny to render it.

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.


  1. 在ui.R中 mailto

  1. Have the mailto in ui.R

该代码需要在用户的最后(可能在临时文件夹中)下载 datatable ,并将其附加在那里。

The code would need to download the datatable at the user's end (probably in the temp folder), and attach it there.


  1. 在server.R中 mailto

您需要保存在服务器上的csv文件才能将其作为附件加载,您需要在 renderUI(),并将文件从您的服务器传递到用户的最后。

You'll need the csv file already saved on your server in order to load it as an attachment. You would need to use the above code inside a renderUI() and also pass the file from your server to the user's end.

有一个 downloadHandler()功能,允许用户从上述可能使用的服务器下载。

There is a downloadHandler() function which allows users to download from the server which could be of use for the above.

我从来没有尝试过传递在您正在尝试的周围,tupachments,但上述逻辑应该允许您创建一个电子邮件,并让您在正确的路径附加文件。

I've never tried passing attachments around as you are trying, however the above logic should both allow you to create an email, and get you on the right path to attaching files.

这篇关于使用TableTools或其他方式在Shiny中添加电子邮件按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆